Home > Assignments > Tradeoffs: basic OO vs Strategy Pattern

Tradeoffs: basic OO vs Strategy Pattern

Joe’s problem is that he wants to use inheritance to update the new duck classes, yet he didn’t realize that he actually didn’t want all of the subclasses to receive the new method he added. His next problem, and his largest, is the fact that he is going to need to make changes/updates/additions to the software many times in the future, and using inheritance certainly will make those changes very difficult. Joe is planning accordingly for code reuse, yet his first idea of inheritance can only help him so much so he needs to find another way of implementing the changes to allow for both code reuse and maintainability.

One certain disadvantage of the Strategy Pattern over basic OO inheritance is that the pattern would not be necessary for a smaller class hierarchy that does not need many future changes or updates. Although one should expect to make future changes and plan accordingly, the added complexity and code (of implementing the Strategy Pattern) may not be justified by the basic class hierarchy. It may even be quicker to make the changes in the future as they arise rather than take the time to implement the Strategy Pattern.

The Strategy Pattern looks like it adds too much complexity for small inheritance trees, yet it allows for the easy creation and integration of new subclasses in the future. It also allows the programmer to edit code only once without having to edit the code of 47 subclasses; basically it allows for easy maintenance.

Advertisements
Categories: Assignments Tags: ,
  1. Wei Chen
    January 29, 2008 at 2:33 am

    Your answer is fine, and your code is good. You can consider to use both OO inheritance and Strategy Pattern in one program.

    Chen

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: