Wednesday, August 01, 2007

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
Wednesday, August 01, 2007 6:08:40 PM (GMT Standard Time, UTC+00:00)
 Wednesday, July 18, 2007

As good of a computer science education that I think I received, when I was an IROC (Idiot Right out of College) I was definitely lacking huge in certain areas.  Chief among these were software engineering (which I think I'm a lot better at now) and beyond basic OO, the fine art of Design Patterns.  I've managed to read about half of Head First Design Patterns and actually implement a few at work.  However, I still feel way behind on them overall, so I started a study group with some coworkers.  We'll attack 2 patterns a week.  I'll post notes about them and links to examples in my svn repository.

Enjoy!

Wednesday, July 18, 2007 7:14:34 PM (GMT Standard Time, UTC+00:00)