|
|
|
|
|
Low-coupling / High-cohesion PatternIn computer science, the Low-Coupling / High-Cohesion isn't a specific pattern amongst design patterns. It's a general method for structuring programs so that they're simpler to understand, program and mantain. This concepts (Low-Coupling / High-Cohesion) are usually related. Low coupling implies high cohesion and viceversa, because if we put together all relationed methods (High Cohesion), the connection between classes tends to get lower (Low Coupling). Low Coupling Coupling is a measure of how strongly one class is connected to another and is increased between Class A and Class B when: - A has an attribute that refers to (is of type) B.
- A calls on services of a B object.
- A has a method which references B (via return type or parameter).
- A is a subclass of (or implements) B.
The disadvantages of high coupling includes: - A change in one class forces a ripple of changes in other classes.
- Difficult to understand a class in isolation.
- Difficult to reuse a class because dependent class must also be included.
High Cohesion If we want to design classes to increase the likelihood of reuse and not be overwhelmingly complex, keeping complexity manageable, the solution is assigning responsibilities so that cohesion remains high. Cohesion is a measure of how strongly related and focused the responsibilities of a single class are. Cohesion is decreased when: - The responsibilities (operations) of a class have little in common.
- Operations do many varied activities, often using varied data.
The disadvantages of weak cohesion are: - Difficult to understand.
- Difficult to maintain, beacause it is constantly effected by changes.
- Difficult to reuse a class because most application wont need a random set of operations attached to a class.
|
 |
|
| Copyright 2005-2009 OnPedia.com. All Rights Reserved |
|
|