Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 1 Good Methods. Slide 2 Cohesion and Coupling l For structured design These software metrics were used extensively Proven to be effective l For.

Similar presentations


Presentation on theme: "Slide 1 Good Methods. Slide 2 Cohesion and Coupling l For structured design These software metrics were used extensively Proven to be effective l For."— Presentation transcript:

1 Slide 1 Good Methods

2 Slide 2 Cohesion and Coupling l For structured design These software metrics were used extensively Proven to be effective l For object-oriented design Not clearly understood or effectively used No historic proof of effectiveness

3 Slide 3 Cohesion l Measure of degree of interaction within a module l Measure of the strength of association of the elements inside a module l Functionality inside a module should be so related that anyone can easily see what the module does l Goal is a highly cohesive module

4 Slide 4 Levels of Cohesion in Structured Design l Functional cohesion(Good) l Sequential cohesion l Communicational cohesion l Procedural cohesion l Temporal cohesion l Logical cohesion l Coincidental cohesion(Bad)

5 Slide 5 Comparison of Cohesion Levels for Structured Design Cohesion LevelCleanliness of Implementation ReusabilityModifiabilityUnderstand- ability FunctionalGood SequentialGoodMediumGood CommunicationalGoodPoorMedium ProceduralMediumPoorVariable TemporalMediumBadMedium LogicalBad Poor CoincidentalPoorBad

6 Slide 6 Cohesion l For structured design Deals with the cohesion of the actions in a module (unit) to perform one and only one task l For object-oriented methods Deals with the ability of a module to produce only one output for one module

7 Slide 7 Levels of Cohesion for Object-oriented Methods l Functional cohesion(Good) l Sequential cohesion l Communicational cohesion l Iterative cohesion l Conditional cohesion l Coincidental cohesion(Bad)

8 Slide 8 Functional Cohesion for Object-oriented Methods l Only one output exists for the module l Ideal for object-oriented paradigm

9 Slide 9 Functional Cohesion for Object-oriented Methods public void deposit (double amount) { balance = balance + amount; }

10 Slide 10 Sequential Cohesion for Object-oriented Methods l One output is dependent on the other output l Modifications result in changing only one instance variable

11 Slide 11 Sequential Cohesion for Object-oriented Methods public double withdraw (double amount, double fee) { amount = amount + fee; if (amount < 0) System.out.println (“Error: withdraw amount is invalid.”); else if (amount > balance) System.out.println (“Error: Insufficient funds.”); else balance = balance – amount; return balance; }

12 Slide 12 Communicational Cohesion for Object-oriented Methods l Two outputs are dependent on a common input

13 Slide 13 Communicational Cohesion for Object-oriented Methods public void addCD (String title, String artist, double cost, int tracks) { if (count = = collection.length) increaseSize ( ); collection [count] = new CD (title, artist, cost, tracks); totalCosts = totalCosts + cost; count++; }

14 Slide 14 Iterative Cohesion for Object-oriented Methods l Two outputs are iteratively dependent on the same input

15 Slide 15 Iterative Cohesion for Object-oriented Methods void formDet (float Equations[2][3], float x[2][2], float y[2][2], float D[2][2]) { for (int Row = 0; Row < 2; ++Row) for (int Col = 0; Col < 2; ++Col) { x[Row][Col] = Equations[Row][Col]; y[Row][Col] = Equations[Row][Col]; D[Row][Col] = Equations[Row][Col]; } x[0][0] = Equations[0][2]; x[1][0] = Equations[1][2]; y[0][1] = Equations[0][2]; y[1][1] = Equations[1][2]; }

16 Slide 16 Conditional Cohesion for Object-oriented Methods l Two outputs are conditionally dependent on the same input

17 Slide 17 Conditional Cohesion for Object- oriented Methods public boolean checkBookIn ( ) { if (this.isAvailable ( )) { //this object cannot be checked out System.out.println (“Error: “ + callNumber + “ is not checked out”); return false; } else { dueDate = null; availability = true; return true; }

18 Slide 18 Coincidental Cohesion for Object-oriented Methods l Two outputs have no dependence relationship with each other and no dependence relation on a common input

19 Slide 19 Coincidental Cohesion for Object-oriented Methods public void readInput ( ) { System.out.println (“Enter name of item being purchased: “); name = MyInput.readLine ( ); System.out.println (“Enter price of item: “); price = MyInput.readLineDouble ( ); System.out.println (“Enter number of items purchased: “); numberBought = MyInput.readLineInt ( ); }

20 Slide 20 Coincidental Cohesion for Object-oriented Methods public String AcceptItemName ( ) { System.out.println (“Enter name of item being purchased: “); name = MyInput.readLine ( ); return name; }

21 Slide 21 Cohesion Decision Tree for Object- oriented Methods

22 Slide 22 Coupling l Measure of degree of interaction between two modules l Measure of interdependence of modules l Goal is to have so little coupling that changes can be made within one module without disrupting other modules

23 Slide 23 Types of Coupling for Structured Methods l Data(Good) l Stamp l Control l Common l Content(Bad)

24 Slide 24 Comparison of Coupling Types for Structured Design Coupling TypeSusceptibility to Ripple Effect Modifiability Understand- ability Module’s Usability in Other Systems DataVariableGood StampVariableMedium ControlMediumPoor CommonPoorMediumBad ContentBad

25 Slide 25 Data Coupling for Structured Methods l Just the data needed is passed between the calling and called modules through calling parameters

26 Slide 26 Data Coupling for Structured Methods Compute Bill Calculate Interest Interest Bill Amount

27 Slide 27 Stamp Coupling for Structured Methods l Whole data structure being passed as a parameter to a module but the module needs only part of data in the data structure l Types of stamp coupling: natural table record bundle

28 Slide 28 Control Coupling for Structured Methods l One module passes a flag as parameter to control the logic in the other module l Parameter being passed is a control flag which dictates what action to perform within the module l Example: void ProcessTransactions (bool whichFlag, DataRec data, bool& successFlag);

29 Slide 29 Common Coupling for Structured Methods l Use of global data l Two modules have access to the same data l Why not? Hard to maintain (ripple effect) Decreases reusability Hard to debug Data change Module change

30 Slide 30 Content Coupling for Structured Methods l One module reaches into the internal code of another module to grab or deposit data or to control its function

31 Slide 31 Coupling Decision Tree for Structured Methods

32 Slide 32 Coupling Example p rs q tu 1 2 3 4 56 #inout 1Aircraft typeStatus flag 2---List of aircraft parts 3Function code--- 4 List of aircraft parts 5Part numberPart manufacturer 6Part numberPart name p, t, and u access the same database in update mode

33 Slide 33 Coupling Example pqrstu p DataData or Stamp Common q ControlData or stamp r Data s t Common u

34 Slide 34 Levels of Coupling for Object-oriented Methods l No coupling(Good) l Sequential coupling l Computational coupling l Conditional coupling l Common coupling l Content coupling(Bad)

35 Slide 35 No Coupling for Object-oriented Methods l No global data sharing or functional calls between two modules

36 Slide 36 Sequential Coupling for Object-oriented Methods l Two modules exist where the outputs of one module are the inputs of another

37 Slide 37 Computational Coupling for Object-oriented Methods l Two modules exist where one module passes a parameter to another module and the parameter has control or data dependence on the output

38 Slide 38 Conditional Coupling for Object-oriented Methods l One module passes a parameter to another module and the parameter has control dependence on an output

39 Slide 39 Common Coupling for Object-oriented Methods l One module writes to the global data and another module reads from the global data

40 Slide 40 Content Coupling for Object-oriented Methods l One module references the contents of another module

41 Slide 41 Coupling Decision Tree for Object-oriented Methods

42 Slide 42 Coupling Decision Tree for Object-oriented Methods From this point forward, Design Reviews will be done using these metrics.


Download ppt "Slide 1 Good Methods. Slide 2 Cohesion and Coupling l For structured design These software metrics were used extensively Proven to be effective l For."

Similar presentations


Ads by Google