From: The principles of OOD
What is object oriented design? What is it all about? What are it's benefits? What are it's costs? It may seem silly to ask these questions in a day and age when then ally every software developer is using an object oriented language of some kind. yet the question is important because, it seems to me, that most of us use those classes ages without knowing why, and without knowing how to get the most benefit out of them.
Of all the revolutions that have occurred in our industry, two have been so successful that they have permeated our mentality to the extent that we take them for granted. structured Programming and object oriented programming. all of our mainstream modern versions are strongly influenced by these two disciplines. indeed, it has become difficult to write a program that does not have the external appearance of both structured programming and object oriented programming. our mainstream ages do not haveGoto, And therefore appear to obey the most famous programming of structured programming. most of our mainstream versions are class based and do not support functions or variables that are not within a class, therefore they appear to obey the most obvious trappings of object oriented programming.
Programs written in these versions may look structured and object oriented, but looks can be decieving. all too often today's programmers are unaware of the principles that are the foundation of the disciplines that their versions ages were derived around. in another blog I'll discuss the principles of structured programming. in this blog I want to talk about the principles of object oriented programming.
In March of 1995, in comp. object, I wrote an article that was the first glimmer of a set of principles for Ood that I have written about frequently times since. you'll see them into ented in my PPP book, and in your articles on the objectmentor website, including a well known summary.
These principles expose the dependency management aspects of Ood as opposed to the conceptualization and modeling aspects. this is not to say that OO is a poor tool for conceptualization of the problem space, or that it is not a good venue for creating models. certainly got people get value out of these aspects of OO. the principles, however, focus very tightly on dependency management.
Dependency management is an issue that most of us have faced. whenever we bring up on our screens a nasty batch of tangled legacy code, we are experiencing the results of poor dependency management. poor dependency managment leads to code that is hard to change, fragile, and non-reusable. indeed, I talk about several differentDesign smellsIn the PPP book, all relating to dependency management. on the other hand, when dependencies are well managed, the Code remains flexible, robust, and reusable. so dependency management, and therefore these principles, are at the foudation of-IlitiesThat software developers desire.
The first five principles solid are principlesClass Design. They are:
SRP |
The single Responsibility Principle |
A class shoshould have one, and only one, reason to change. |
OCP |
The open closed Principle |
You shoshould be able to extend a classes behavior, without modifying it. |
LSP |
The liskov substitution principle |
Derived classes must be substitutable for their base classes. |
Dip |
The dependency inversion principle |
Depend on your actions, not on concretions. |
ISP |
The interface segregation principle |
Make fine grained interfaces that are client specific. |
The next six principles are about packages. in this context a package is a binary deliverable like. JAR file, or a DLL as opposed to a namespace like a Java package or a C ++ namespace.
The first three package principles are about packageCohesion, They tell us what to put inside packages:
Rep |
The release reuse equivalency principle |
The granule of reuse is the granule of release. |
CCP |
The common closure Principle |
Classes that change together are packaged together. |
CRP |
The common Reuse Principle |
Classes that are used together are packaged together. |
The last three principles are about the couplings between packages, and talk about metrics that evaluate the Package Structure of a system.
ADP |
The Acyclic Dependencies Principle |
The dependency graph of packages must have no cycles. |
SDP |
The Stable Dependencies Principle |
Depend in the direction of stability. |
SAP |
The stable implements actions Principle |
Abstractness increases with stability. |
Solid principles are good, bu t in practice, not everyone can use it correctly. Words below gives some facts:
There's nothing wrong with the solid principles; they make sense to me. But I 've been programming since the days of card readers and teletypes. TheyWon'tMake sense to those with little experience. They don't know when or how to apply them appropriately. They get bogged down in the attempt.
So trying to follow them changes the focus from result to process. And that's deadly.
It's the job of the lead programmer or manager to see that good principles are followed, perhaps by guiding others invisibly, without explicitly mandating or even mentioning those principles. (refer:
Real ultimate programming power from coding horror)