Design Principles
Software always changes like an evolving organism. Each change has a ripple effect through the system like tossing a pebble into the water. Ideally, the ripples are confined and have no adverse consequences.
A good software design organizes the code in a way that it is "easy to understand, change, maintain and reuse."
In a small application, poor design is survivable! The problem with poorly designed small applications is that if they are successful, they grow up to be poorly designed big applications!
In this module, we will set out to learn more about good practices when it comes to software design.
It is often said that design cannot be taught but has to be learned through experience. That said, there is always the opportunity to learn from the experience of others.
Over the years, programmers noticed that some code arrangements made their lives easier while others made them harder. These experiences led them to develop opinions about how to write good code.
Design principles are (often opinionated) guidelines derived from the experience of programmers about software design that usually take the form of dos and don'ts. They are the Commandments of OO Programming.
We have already explored two principles: High cohesion and low coupling.
-
High cohesion means that the responsibilities of a given element are strongly related and highly focused.
-
Coupling is a measure of how strongly one element is connected to, has knowledge of, or relies on other elements. The low coupling means lower dependency between the classes.
High cohesion is generally used in support of low coupling.
The path to changeable and maintainable object-oriented software begins with classes that are highly cohesive and loosely coupled.
We now pick up that discussion by introducing a catalog of design guidelines known as the SOLID principles.
The SOLID design principles
The SOLID design principles were promoted by Robert C. Martin and are some of the best-known design principles in object-oriented software development. SOLID is a mnemonic acronym for the following five principles:
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
In the following readings, we explore these principles one by one.