SOLID

In this entry, I'll go over the SOLID principles of OOP Programming and design. Next week I'll review the LIQUID principles (har, har). Interestingly enough, the first person to define the principles was Bob Martin, it seems like the MCU of Software Design and Architecture.

As one might infer from the acronym, the SOLID principles are 5.

Single Responsibility Principle

Open/Closed Principle

Liskov Substitution Principle

Interface Segregation Principle

Dependency Inversion Principle

I'm not entirely sure what to do with this entry. Sure I could make a summary of each principle, although the initial article is short to begin with. I guess not short enough, though. I'll cover each principle in about 20 words or less, using the title as a descriptor.

1. Single Responsability, it means that a class should do one thing only. No "clamp value but also sometimes add 5 to it".

2. Open/Closed, (wikipedia link down) If a class inherits from a base class, don't mess with them by messing with the base class, just extend it.

3. Liskov Substitution, I'll get back to that one, just use sealed in C# or final in Java.

4. Interaface Segregation, an interface is wearing many hats? Make more, with hats that actually fit the interface.

5. Dependency Inversion, Depend on interfaces, abstract classes, not actual classes.

Sometimes it happens that I look at all these guidelines, rules, principles, code smells, I dunno, it may seem overwhelming at times. One thing is for certain, and that is that I may use more that one eventually, and hopefully these come back to me when I need them. For now, listing them and somewhat understanding them should hopefully be enough. I remember last week's entry on Software craftsmanship, and how Bob said that nowadays (6 years ago by now), IDEs are smart enough to help out programmers, and in this SOLID principles article, it would seem that IDEs know how to use them well enough, so I'll put my faith in that, he he.

Comments