More about design

Until now I have written about the main principles of OO design and some other parts of the software development.

On this post I am going to talk about three interesting design principles that are very useful to the design of an application.

  • The first principle is the Open-Closed Principle (OCP) and is about flexibility and goes beyond inheritance.

It allows some modifications but, with the minimum changes in the existing code. This means that once you defined your classes no one will modify it, preventing of integrity changes. It also is called (closed for modifications).

But consider the case that someone needs to add some new features, you need to let them subclass the class to override the method that you created. This is also called (open for extension).

  • Then the second principle is don’t repeat principle (DRP) and is about avoiding the repeated code by abstracting out things that are common and making it simple.

If your system has each piece of information and behavior in the correct place. The system success in DRP.

  • The third principle: the single responsibility principle (SRP) this last one is about the responsibilities of each object. In this part you specify also which object do what in the system.

Is recommendable that each object should have only one responsibility to accomplish.

Finally, there is another part to consider, the well-designed inheritance of the system.

In this part you assure the correct place of the classes and if is needed to change a subclass for the father class that could be done. You need to analyze the correct form of your classes, I mean if they are going to be composed or aggregated these are two form of inheritance an you need to think about it when you design that part.

References:

Advertisements

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s