Strategy
Notes:
shove dynamic behavior into interfaces. have the main base compose the behavior interfaces. Then you can dynamically assign the behavior interface instances in the child classes of the main base class.
Decorator:
Basically think of an abstract class like a vehicle. Then you have a couple of classes inherited directly off of it: truck, bike broken down Chevy, etc. Then u have a base decoration class, which inherits off of vehicle and also contains a member instance of vehicle, so it both "has a" and "is a" vehicle, and has a constructor that takes a vehicle type. Next, you've got a bunch of decorations, each of which inherits off of the root decoration class, such as pimped out, racing striped, washed, waxed, painted pink, etc.
So in code, you can create any of these decorations and pass them in a vehicle or a decorated vehicle. This way you can have pink truck just as easily as you can have a pimped out-washed-waxed-racing striped broken down Chevy, without having to create a complicated inheritance tree for each possible combination.
- Some Notes:
sort of define your own inheritance tree on the fly - defines an "is a"/"has a" relationship between the decorations and the object they're decorating
- one possible use: to dynamically aggregate functionality of semi-heterogenous items
- composition + inheritance