The Dynamic Duo of Design Principles
the Single Responsibility and Open / Closed Principles
Four Pillars | Principles | Dynamic Duo | Thoughts | |
Select a content section anchor button and then use the Browser’s back button to return to selections |
The Four Pillars of Modern OOP
Modern object oriented programming (OOP) is based on the Four Pillars of Object Oriented Programming:
-
Encapsulation – Details required to return a result from a Class Method should be Hidden from the Calling Method
-
Inheritance – The Ability to enable Objects to Share Common Functionality of the Parent Object. Inheritance promotes the Reuse of existing Object’s Code Elements
-
Polymorphism – The Ability to derive different concrete behaviors from a Common Abstract Type
-
Data Abstractions – The Encapsulation of data within a Single Object that includes Primitives and other Complex Objects as Related Members
To realize the benefits that OOP promises the Modern Developer must embrace the S.O.L.I.D. Design Principles.
The Core and Code Principles
The two principles that must be implemented in every day development are the Single Responsibility Principle and the Open / Closed Principle.
The Modern Developer (TMD) has supplemented the basic five S.O.L.I.D. Principles with two additional Core Principles.
TMD has created five Code Principles to help the Modern Developer deliver better quality code that reduces the Total Cost of Ownership of the code base over the Software Development Life Cycle (SDLC).
The Dynamic Duo
Robert Martin presented the concept of the Five Development Principles to the world in the early 2000’s.
These principles where later coined by Michael Feathers in to the “Acronym of Acronyms”: S.O.L.I.D.
SRP is the “S” and OCP is the “O” in the S.O.L.I.D. Design Principles.
The Open/Closed Principle states:
“A Software Entity Should be Open for Extension but Closed for Modification”
The intent of this principle is to “Encapsulate the Details” of a dependency block of code away from the Class Method using the code
block as, more than likely, is not part of the Responsibility of that Method.
OCP should “Data Hide” the low-level details
of the actions that a method
depends on for the result
The major problem by not compiling with OCP is that any change to the low-level details of the code block requires you to “Open” the calling Class.
You need to make changes to the method’s code block that has no responsibility to the calling Software Entity to understand the low-level details.
You run the risk of breaking a Software Entity that has nothing to do with the dependency changes you have been task to change.
This violation of OCP also violates the Single Responsibility Principle (SRP).
The Single Responsibility Principle states:
“A Software Entity Should have One and Only One Reason to Change”
This is the most important principle of them all
The intent of this principle is to prevent Classes and Methods from exploding into Fat Class Entities that are impossible to understand and maintain.
Classes and Methods that violate
SRP open the solution to corruption
Corruption occurs in code when changes affect application areas that have nothing to do with the changes being made.
A Software Entity becomes vulnerable to the introduction of undesirable artifacts.
These artifacts become very difficult to debug over the life cycle of the assembly.
SRP Violations Create Very Brittle Code
and Needlessly Becomes Tightly Coupled
to Unrelated Code Blocks
Your Code will improve a magnitude if it ONLY complies with these two of the twelve Modern Developer’s Design Principles.
By following the five S.O.L.I.D Design Principles for thought process will change dramatically.
By adding the remaining Modern Developer’s Core and Code Principles you will add style to the Art and the Science of your development.
The Modern Developer’s Design Principles are Organized into Two Categories:
These Principles Creates the
Modern Developer’s “Paradigm of Thought”
Concluding Thoughts
A methodical development approach is required in development and it starts with Test Driven Development (TDD).
By defining the “What” of your development effort before trying to develop the “How” TDD presents the opportunity to implement the Code and Core Principles during the “Refactoring” stage of the Red, Green, Refactoring framework of Test Driven Development.
The Dynamic Duo of the Core Principles
is your Gift to your Client
in the form of World Class Deliveries
Wisdom Pearl # 121 – Work Quality Concept
Your Work is Only as Good
… As How it is Perceived by the Next Person who Touches It
Positive Acceptance of your Work is Your Preeminent Responsibility
The following two tabs change content below.
I am a Principal Architect at Liquid Hub in the Philadelphia area specializing in Agile Practices as a Certified Scrum Master (CSM). I use Test Driven Development (TDD) and Acceptance Test Driven Development (ATDD) with Behavior Driven Development (BDD) as my bridge to Agile User Stories Acceptance Criteria in a Domain Driven Design (DDD) implementing true RESTful services
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016