CSC/ECE 517 Fall 2009/wiki1b 13 zz: Difference between revisions
No edit summary |
|||
Line 21: | Line 21: | ||
</blockquote> | </blockquote> | ||
It is a very simple and atomic principle. It is a direct derivation of the Dependency Inversion Principle [http://ifacethoughts.net/2006/03/16/dependency-inversion-principle-and-interface/]. This principle enables high reusability and easier maintenance of software applications. To explain the principle further we need to understand a few terms | It is a very simple and atomic principle. It is a direct derivation of the Dependency Inversion Principle [http://ifacethoughts.net/2006/03/16/dependency-inversion-principle-and-interface/]. This principle enables high reusability and easier maintenance of software applications. To explain the principle further we need to understand a few terms like stability, dependencies etc in more detail. | ||
==Stability== | ==Stability== | ||
What does stability mean? By simply goggling stability, we get definitions like resistance to change, reliability etc [http://www.answers.com/topic/stability]. Thus it roughly means "hard to change", whereas instability means "easy to change". | What does stability mean? By simply goggling stability, we get definitions like resistance to change, reliability etc [http://www.answers.com/topic/stability]. Thus it roughly means "hard to change", whereas instability means "easy to change". | ||
Consider an example, in which you stand a penny on its side. Is this penny stable in that position? Mostly people would answer a no, even though it does not change its position for a very long time. Thus, stability has nothing directly to do with the frequency of change. It more relates to the amount of work required to make a change. The penny is not stable because it takes little work to topple it. | Consider an example, in which you stand a penny on its side. Is this penny stable in that position? Mostly people would answer a no, even though it does not change its position for a very long time. Thus, stability has nothing directly to do with the frequency of change. It more relates to the amount of work required to make a change. The penny is not stable because it takes little work to topple it [http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf]. | ||
Thus stability of a software package would depend on various factors like size, complexity, clarity, etc. But with respect to our principle, stability focus on a different factor. A software package would be difficult to change, if it has lots of other software packages depend on upon it. Thus a package with lots of incoming dependencies is very stable because it requires a great deal of work for any change to propagate with all the dependent packages. | Thus stability of a software package would depend on various factors like size, complexity, clarity, etc. But with respect to our principle, stability focus on a different factor. A software package would be difficult to change, if it has lots of other software packages depend on upon it. Thus a package with lots of incoming dependencies is very stable because it requires a great deal of work for any change to propagate with all the dependent packages. | ||
==Stability and Dependencies== | |||
With the above definition of stability, you don't want to increase stability of the packages as your software can not change easily then. But if the system has been designed well then hard to change packages or stable packages will not change that frequently. Thus, we need to understand the relationship between stability and dependencies. | |||
Consider a following example, Here package x, depends on three other packages. Thus, it is said that x is responsible to the other three packages. On other hand, x does not depend on anything, thus it does not influence any other change. It is said to be independent [http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf]. | |||
[[Image:2-25.jpg|centre]] | |||
Another example, here package y has no packages depending upon it, thus we call it irresponsible. It is very instable package. But there are three other packages that y depends upon, so changes from these three external packages may affect it and thus we say y is dependent. | |||
[[Image:2-26.jpg|centre]] | |||
Thus we need to be careful while designing packages especially lower level packages (which would have more users) and higher level packages (which would tend to have fewer users). | |||
==Stability Metrics== | ==Stability Metrics== | ||
Line 61: | Line 75: | ||
Thus according to the Stable Dependencies Principle I metric of the package should be greater than the I metric of the packagesit depends upon thereby showing that I metrics decrease in the direction of dependency. | Thus according to the Stable Dependencies Principle I metric of the package should be greater than the I metric of the packagesit depends upon thereby showing that I metrics decrease in the direction of dependency. | ||
Revision as of 19:54, 18 November 2009
Bob Martin's Stable Dependencies Principle says, "The dependencies between packages should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable than it is."
Bob Martin
Robert C. Martin (Uncle Bob) defines the domain of design patterns to be the architecture of systems modules (packages, classes and components) and their interconnections. His design patterns address the four major reasons for failure of the systems: rigidity, fragility, immobility and viscosity [1].
Following are the list of few design principles quoted by him to avoid the pitfalls associated with unsuccessful software engineering, Reuse/Release Equivalence Principle, Common Closure Principle, Common Reuse Principle, Acyclic Dependencies Principle, Staple Dependencies Principle, Stable Abstraction Principle.
The objective of this article is to discuss in detail Stable Dependencies Principle. Each of the four problems discussed above can be caused by improper dependencies between the modules of the software. It is the dependency architecture that degrades the ability of the software to be maintained. The Stable Dependencies Principle is one of the principle which discusses its concern with coupling of packages, or the degree to which they rely on each other.
Stable Dependencies Principle
Principle: The dependencies between packages should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable than it is.
It is a very simple and atomic principle. It is a direct derivation of the Dependency Inversion Principle [2]. This principle enables high reusability and easier maintenance of software applications. To explain the principle further we need to understand a few terms like stability, dependencies etc in more detail.
Stability
What does stability mean? By simply goggling stability, we get definitions like resistance to change, reliability etc [3]. Thus it roughly means "hard to change", whereas instability means "easy to change".
Consider an example, in which you stand a penny on its side. Is this penny stable in that position? Mostly people would answer a no, even though it does not change its position for a very long time. Thus, stability has nothing directly to do with the frequency of change. It more relates to the amount of work required to make a change. The penny is not stable because it takes little work to topple it [4].
Thus stability of a software package would depend on various factors like size, complexity, clarity, etc. But with respect to our principle, stability focus on a different factor. A software package would be difficult to change, if it has lots of other software packages depend on upon it. Thus a package with lots of incoming dependencies is very stable because it requires a great deal of work for any change to propagate with all the dependent packages.
Stability and Dependencies
With the above definition of stability, you don't want to increase stability of the packages as your software can not change easily then. But if the system has been designed well then hard to change packages or stable packages will not change that frequently. Thus, we need to understand the relationship between stability and dependencies.
Consider a following example, Here package x, depends on three other packages. Thus, it is said that x is responsible to the other three packages. On other hand, x does not depend on anything, thus it does not influence any other change. It is said to be independent [5].
Another example, here package y has no packages depending upon it, thus we call it irresponsible. It is very instable package. But there are three other packages that y depends upon, so changes from these three external packages may affect it and thus we say y is dependent.
Thus we need to be careful while designing packages especially lower level packages (which would have more users) and higher level packages (which would tend to have fewer users).
Stability Metrics
Stability metrics determine the stability of a package which is calculated by counting the number of dependencies that enter and leave the package.
The Instability metric I is given as
I = Ca/(Ca +Ce)
where,
Ca --> The number of incoming dependencies or Afferent Couplings
Ce --> The number of outgoing dependencies or Efferent Couplings
The value of I is always between 0 and 1.
- I = 0 is a Stable Package. In this case, other packages have a dependency on this package but it does not depend on any other packages, hence responsible and independent.
- I = 1 is an Instable Package. Here, no other packages have a dependency on this package but this package depends on the other packages, hence irresponsible and dependent.
The values Ca and Ce are calculated by counting the number of classes outside the package that have dependencies with the classes inside the package being considered. A figure explaining how the metric can be calculated is shown below
In the above example we can compute the Instability metric of the package in the center. Here the dashed arrows represent package dependencies.
Here Ca, which is the number of classes outside the package at center that depend upon the classes within this package is equal to 4. Whereas Ce, which is the number of classes inside the package at center that depend upon classes outside this package is 3. Hence I = 3/7.
Thus according to the Stable Dependencies Principle I metric of the package should be greater than the I metric of the packagesit depends upon thereby showing that I metrics decrease in the direction of dependency.