Nerd For Tech
Published in

Nerd For Tech

Principles of Object-Oriented Design

Apart from Abstraction, Polymorphism, Inheritance, and Encapsulation there are principles to be followed in coding these concepts are the result of decades of software engineering experience. They are the result of the collaboration and writings of a vast number of software developers and researchers, rather than the work of a single intellect. Although they are referred to as object-oriented design principles, they are actually particular examples of long-standing software engineering concepts.

title overview

There are five principles of class design (aka SOLID):

1. The Single Responsibility Principle (SRP)
A class should have only one reason to change.

2. The Open-Closed Principle (OCP)
Software entities (classes, packages, methods, etc.) should be open for extension but closed for modification.

3. The Liskov Substitution Principle (LSP)
Subtypes must be substitutable for their base types.

4. The Interface Segregation Principle (ISP)
Clients should not be forced to depend upon methods that they do not use. Interfaces belong to clients, not to hierarchies.

5. The Dependency Inversion Principle (DIP)
Abstractions should not depend upon details. Details should depend upon abstractions.

package cohesion

There are three principles of package cohesion

1. The Reuse Release Equivalence Principle (REP)
The granule of reuse is the granule of release.

2. The Common Closure Principle (CCP)
The classes in a package should be closed together against the same kinds of changes. A change that affects a closed package affects all the classes in that package and no other packages.

3. The Common Reuse Principle (CRP)
The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.

package coupling

There are three principles of package coupling

1. The Acyclic Dependencies Principle (ADP)
Allow no cycles in the dependency graph.

2. The Stable Dependencies Principle (SDP)
Depend on the direction of stability.

3. The Stable Abstractions Principle (SAP)
A package should be as abstract as it is stable.

Reference: https://stackoverflow.com/a/399737/12100518, http://wiki.c2.com/?PrinciplesOfObjectOrientedDesign, https://slideplayer.com/slide/13461533/, https://medium.com/nerd-for-tech/introduction-to-solid-design-principles-94a9394eb84e

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store