Presentation is loading. Please wait.

Presentation is loading. Please wait.

SWE © Solomon Seifu 2010 1 ELABORATION. SWE © Solomon Seifu 2010 2 Lesson 12-3 Cohesion.

Similar presentations


Presentation on theme: "SWE © Solomon Seifu 2010 1 ELABORATION. SWE © Solomon Seifu 2010 2 Lesson 12-3 Cohesion."— Presentation transcript:

1 SWE © Solomon Seifu 2010 1 ELABORATION

2 SWE © Solomon Seifu 2010 2 Lesson 12-3 Cohesion

3 SWE © Solomon Seifu 2010 3 SWE: Elaboration - Cohesion A measure of relatedness of the code in a given class A measure of how well the lines of source code within a module work together to provide a specific piece of functionality Cohesion is a measure of degree of how strongly a class focuses on its responsibilities

4 SWE © Solomon Seifu 2010 4 SWE: Elaboration - Cohesion (Cont.) High cohesion: This means that a class is designed to carry on a specific and precise task  Using high cohesion, methods are easier to understand, as they perform a single task Low cohesion: This means that a class is designed to carry on various tasks  Using low cohesion, methods are difficult to understand and maintain

5 SWE © Solomon Seifu 2010 SWE: Elaboration – Cohesion Types Coincidental cohesion Logical cohesion Temporal cohesion Procedural cohesion Communicational cohesion Functional cohesion Informational cohesion

6 SWE © Solomon Seifu 2010 6 SWE: Elaboration – Cohesion (Coincidental Cohesion) A module has coincidental cohesion if it performs multiple, completely unrelated operations Coincidental Cohesion is bad for the following reasons:  Such modules degrade the maintainability of the product, both corrective maintenance and enhancement  These modules are not reusable

7 SWE © Solomon Seifu 2010 7 SWE: Elaboration – Cohesion: (Coincidental Cohesion) (Cont.) A class exhibits coincidental cohesion if the tasks its methods perform are totally unrelated tasks class Coincidental { void initPrinter() {.. } double calcInterest() {.. } Date getDate() {... } }

8 SWE © Solomon Seifu 2010 8 SWE: Elaboration – Cohesion (Logical Cohesion) (Cont.) For example, the methods of the following class are related by the mathematical concept of area class Logical { double circleArea() {... } double rectangleArea() {... } double triangleArea() {... } } A class exhibits logical cohesion if its methods perform conceptually related tasks

9 SWE © Solomon Seifu 2010 9 SWE: Elaboration – Cohesion (Temporal Cohesion) (Cont.) For example, the methods of the following class are related by the device initialization concept, and they are all invoked at system boot time class Temporal { void initDisk() {... } void initPrinter() {... } void initMonitor() {... } } A class has temporal cohesion when it performs a series of operations related in time

10 SWE © Solomon Seifu 2010 10 SWE: Elaboration – Cohesion (Coincidental, Logical & Temporal Cohesions) One reason why coincidental, logical, and temporal cohesion are at the low end of our cohesion scale is because instances of such classes are unrelated to objects in the application domain. For example, suppose x and y are instances of the Temporal class:  Temporal x = new Temporal(), y = new Temporal();  How can we interpret x, and y? What do they represent? How are they different?

11 SWE © Solomon Seifu 2010 11 SWE: Elaboration – Cohesion (Procedural Cohesion) A class has procedural cohesion if it performs a series of operations related by the sequence of steps to be followed by the product (the result/outcome) In the Procedural class example, the outcome can be a cake or anything that is baked class Procedural { void addIngredients() {.. } void mix() {... } void bake() {... } }

12 SWE © Solomon Seifu 2010 12 SWE: Elaboration – Cohesion (Communicational Cohesion) A class has communicational cohesion if it performs a series of operations related by the sequence of steps to be followed by the product and if all the operations are performed on the same data E.g., UpdateRecordInDatabaseAndWriteIt ToTheAuditTrail(); CalculateNewTrajectoryAndSendItToThePrinter();

13 SWE © Solomon Seifu 2010 13 SWE: Elaboration – Cohesion (Functional Cohesion) A method that performs exactly one operation or achieves a single goal has functional cohesion E.g.,  getTempratureOfFurnace(),  ComputeOrbitalOfElectron(),  WriteToHardDrive(), and  CalculateSalesCommission()

14 SWE © Solomon Seifu 2010 14 SWE: Elaboration – Cohesion (Benefits of Functional Cohesion) A module with functional cohesion often can be reused because the one operation it performs frequently needs to be performed in other products A properly designed, thoroughly tested, and well- documented module with functional cohesion is a valuable (economic and technical) asset to any software organization and should be reused as often as possible

15 SWE © Solomon Seifu 2010 15 SWE: Elaboration – Cohesion (Benefits of Functional Cohesion) (Cont.) Maintenance is easier to perform on a module with functional cohesion Functional cohesion leads to fault isolation Because a module with functional cohesion performs only one operation, such a module generally is easier to understand than a module with lower cohesion. This understanding simplifies maintenance Functional cohesion also is valuable when a product has to be extended

16 SWE © Solomon Seifu 2010 16 SWE: Elaboration – Cohesion: Informational Cohesion (Cont.) A class exhibits informational cohesion if the tasks its methods perform operate on the same information or data In object oriented programming this information would be the information contained in the instance variables of an object Only f 1, … f n have access to the shared data. Similar to a class in OO programming language. f 1, … f n are functionally cohesive Shared Data f1f2fn …

17 SWE © Solomon Seifu 2010 17 SWE: Elaboration – Cohesion (Informational Cohesion) (Cont.) For example, the Informational class exhibits informational cohesion because its methods all work on the same information:  the speed, and  altitude of some Airplane object class Informational { private double speed; private double altitude; void takeoff() {..} void fly() {..} void land() {..} }

18 SWE © Solomon Seifu 2010 SWE: Elaboration – Cohesion (Seven Levels [From the Best to the Worst]) Cohesion Informational I Functional Communicational Procedural Temporal Logical Coincidental 18 Best Worst

19 SWE © Solomon Seifu 2010 SWE: Elaboration – Cohesion (Wholeness) Cohesion is a measure of how strongly- related is the functionality expressed by the source code of a software module Functional & informational cohesion are the best form of cohesion Coincidental and logical cohesion are the worst forms of cohesion and must be avoided


Download ppt "SWE © Solomon Seifu 2010 1 ELABORATION. SWE © Solomon Seifu 2010 2 Lesson 12-3 Cohesion."

Similar presentations


Ads by Google