Sie sind auf Seite 1von 3

Cohesion describes the nature of interactions within software module. Types of cohesion: 1. Coincidental. Modules are arbitrarily chopped.

No relationship between components. Modules does not have a meaningful statement of what it accomplishes. 2. Logical cohesion. Modules performs a set of logically similar functions. Example: Output activities are combined in single module: Output anything Compose of: Output text to screen Output line to printer Output record to file // MethodOverload.java public class MethodOverload{ public static void main(String arg[]) { computeFee(1000,.04); computeFee(1000,4); } public static void computeFee(float fee, double rate) { double computedValue; computedValue = fee+fee*rate; System.out.println ("This is the rate with decimal "+computedValue); } public static void computeFee(float fee2, int rate2) { double compValue, r ; r=rate2/100.0; compValue = fee2+fee2*r; System.out.println("This is the integer rate "+compValue); } }

Another example: //Student.java public class Student{ private String name; private int studNo; private double tuitionFee; Student() { name="Cute ako"; studNo=1234; tuitionFee=15000.50; } Student(int studNo2, String name2) { name=name2; studNo=studNo2; } public void setName(String pangalan) { name = pangalan; } public String getName() { return name; } public int getStudNo() { return studNo; } public double getTuitionFee() { return tuitionFee; } }

3. Temporal cohesion. Performs a set of actions whose only relationship is to have carried out the same time. Example is initialization of class using constructor. Mostly common in OOP. 4. Communicational. Functions that act on the same data are grouped together.Example of this a module formats and prints total price. Disadvantage complex, too many things are grouped together. This can be avoided if distinguished and designed as separte modules. 5. Functional cohesion. Best type of cohesion. Perfoms a single, well-defined action on single subject. Example calculate average, print result. Is this possible: Public static void calculateInvestmentAmount( double Principal, double rate) { if (rate>.10) addtlAmount = 1000; else addlAmount =100; totalInvestment = Principal*(1+rate) + addtlAmount; System.out.println(Total investment + totalInvestment); }

COUPLING Interaction between modules. Ideally, modules should be constructed with minimum interaction between modules (low coupling). Individual modules can be coded, tested and amended without the complications of dealing with another modules. Erros are isolated and the damage is limited. If common data are shared, this should be minimized to four parameters. Shared or global data. Data are accessible to all modules. It is difficult to understand. Procedure calls with parameters that are pure data. Information is clear communicated between modules. Passing a serial data stream. Best coupling because it achieves without any transfer of control between modules. One module outputs to a serial file and second module reads it. Outputting module has no acces to the data once it has released it.

Das könnte Ihnen auch gefallen