Chapter 7: One of our favorite state of matter´s principles.

So, we are talking about SOLID in this blog post. No, not our favorite state of matter (that should be plasma, of course) but a group of five principles of object-oriented programming and design. SOLID covers how to program better and cleaner through different principles. I think that these 5 principles come together and forms a “solid” foundation on what and how needs to be done (it took me some days to think of that pun).



The first principle may be pretty straight forward, however, it is often overlooked, leading to the start of some messy code; every class should have exactly one responsibility. While many people avoid following this principle and starts delegating responsibilities to functions inside a class, this can lead to confusion of how a specific class works, and the design of the whole project may start to crumble.

The open/closed principle allows us to make classes ready to be extended if needed, but be closed to modifications, this avoids fragility to the object-oriented code.  I could consider this as using the properties such as inheritance and polymorphism adequately, allowing the extendibility of the base class to fulfill the new requirements without breaking the whole class foundation.

The Liskov Substitution Principle, while similar to the previous principle, it aboard specifically inheritance; to look carefully where an instance of a class is better than inheriting from that class. Sometimes it seems easier to inherit the class and then implement the method, function, or get a value you need; however, it can mess up the code and how the behavior of a class is shaped.

The Interface Segregation Principle covers how it is better to partition an interface into smaller interfaces to avoid making one interface with a lot of responsibilities. Similar to the first principle, this time it is applied to interfaces.

Finally, the Dependency Inversion Principle covers how we can avoid a class dependency by creating an interface of a class and then applying this interface to different classes. This allows class dependency to be interface dependency, avoiding overhead of classes that aren’t needed.

At the end, these SOLID principles can shape up how we can code cleanly and easier, allowing our co-workers (or why not, ourselves) understand thoughtfully our code, permit us expand the use of our code and have a strong foundation in our programs.

References:

Guiness Edward (2013). Understanding the SOLID Principles. Available on: http://webcem01.cem.itesm.mx:8005/s201713/tc3049/solid.html

Comments

Popular posts from this blog

Chapter 4: Architectus Reloadus vs Architectus Oryzus

Chapter 11: Metaprogramming

Chapter 9: Microservice Architecture: A whole new Architectural world.