Presentation is loading. Please wait.

Presentation is loading. Please wait.

DESIGN PATTERNS COUPLING AND COHESION WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO.

Similar presentations


Presentation on theme: "DESIGN PATTERNS COUPLING AND COHESION WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO."— Presentation transcript:

1 DESIGN PATTERNS COUPLING AND COHESION WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1

2 จุดประสงค์การเรียนรู้  เข้าใจความหมายของ coupling และ cohesion  เข้าใจถึงระดับความสัมพันธ์ของ coupling และ cohesion  เข้าใจความสัมพันธ์ระหว่าง coupling และ cohesion 2

3 MEANING Coupling and cohesion are used in analyzing the software design Coupling is degree of interdependence between objects(or classes) Cohesion is measurement of the strength of functional relatedness of elements within a objects Type of coupling and cohesion 3 couplingcohesion loose(low)low tight(high)high

4 COUPLING Tight-Coupling: 1. While creating complex application in java, the logic of one class will call the logic of another class to provide same service to the clients. 2. If class(A) calling class(B) logic then it is called collaboration. 3. When class(A) is collaborating with class(B) then there exists tight-coupling between two classes. 4. If class(A) call the logic of class(B) then class(A) need an object of class(B). It means class(A) create an instance of class(B). 5. For example, there are two classes,traveler and car. Traveler class is calling logic of car class; In this case traveler class creates an object of car class. 6. Instance of car class object depend on(dependency) traveler object. 4

5 TIGHT-COUPLING: 5

6 6

7 LOOSE-COUPLING: 7

8 COHESION: Steve McConnell 8 support a central purpose. Classes that contain strongly related functionality are described as having strong cohesion, and the heuristic goal is to make cohesion as strong as possible. Cohesion is a useful tool for managing complexity because the more code in a class supports a central purpose, the more easily your brain can remember everything the code does. Uncle Bob's Clean Code(cleancoders.com) Classes should have a small number of instance variables. Each of the methods of a class should manipulate one or more of those variables. In general the more variables a method manipulates the more cohesive that method is to its class. A class in which each variable is used by each method is maximally cohesive. In general it is neither advisable nor possible to create such maximally cohesive classes; on the other hand, we would like cohesion to be high. When cohesion is high, it means that the methods and variables of the class are co-dependent and hang together as a logical whole.

9 COHESION: 9 low-cohesion high-cohesion

10 COUPLING AND COHESION 10 Good design software need  loose-coupling and high-cohesion (flexible system)  loosely couple is decouple


Download ppt "DESIGN PATTERNS COUPLING AND COHESION WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO."

Similar presentations


Ads by Google