HFOOAD Chapter 8 – “Originality is Overrated”

In this chapter we were introduced to design principles. These make your software more maintainable, flexible and extensible. These are the following:

  1. Open-Closed Principle
  2. Don’t Repeat Yourself Principle
  3. Single Responsibility Principle
  4. Liskov Subsitution Principle

Open-Close Principle

This principle tells us that classes should not be modified but extended. For example, if you worked on a class, your workmates should not modify your class, but make new classes that inherit from yours.

Don’t Repeat Yourself Principle

This design principle consists in identifying same behavior and abstracting it to just one place. That way if a change needs to be made, you don’t have to change several classes, just the one.

Single Responsibility Principle

This principle suggests that each class should only have one purpose. As it was mentioned in previous chapters, each class should only have one reason to change.

Liskov Substitution Principle

This principle tells us that subtypes should be interchangeable for their base type. For example, if you have the “Animal” class and the “Tiger” class inherits from it. You should be able to treat tiger objects as animal objects without having any problem. If you get a problem by this type of behavior, you are not using this principle the right way.

This chapter also talks about delegation, composition and aggregation.

Delegation is when you hand over a specific behavior from one class to another.

Composition is when a class has other classes as attributes and those other classes need the first class in order to exist. Composition is all about dependency.

Aggregation is just like composition but without the dependency, it’s when a class has other classes as attributes but any of those classes need another to exist.

This chapter focused on specific things, not like the big picture kind of stuff that was present inn previous chapters. I really liked that because it gave me some new tools for designing software projects.

References

McLaughlin B. , Pollice G., West D. (2006). Originality is Overrated. On Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OO&A (640). O’Reilly Media.

Leave a comment