Tuesday, November 06, 2007

Customizable classes for objects

Thoughts on object oriented programming, classes, objects and polymorphism

I am in the middle of a project that involves code from another organization. This organization is trying to make their code as flexible as possible through configuration settings, user only classes and templates. I also maintain code for another system from another organization that provides no flexibility for customization of code. I starting thinking, did some Google searches, and didn't find anything; so I'm putting my thoughts here.

The typical class design model I see in all media is the base class containing all the base functionality then you extend that class one or more times to provide additional logic. So myFoo extends Foo. Foo contains a lot of good methods and logic but my organization needs one additional property and method; myFoo is created. Here is where I start thinking this sucks. Any class that instantiates Foo, must now instantiate myFoo instead.

If the external organization delivers those classes we changed to use myFoo, now we must go back and make those changes again.

Wouldn't it make sense to deliver a Foo that extends a baseFoo, have all the classes that use Foo just use Foo? The developing organization makes changes to the baseFoo classes and the customizing organizations make customizations to the Foo classes.

This method of class design is just as vulnerable to catastrophic changes as the widely taught method. If you change the data schema you will still need to change the data objects, business objects, presentation objects, etc. Nothing will prevent that mess for occurring or, well, being a mess. If, however, a hundred classes use Foo would it make sense to change all (or ones that need) to use myFoo?