Design Principle 2: Increase cohesion Where possible a subsystem or module has high cohesion if it keeps together things that are related to each other, and keeps out other things This makes the system as a whole easier to understand and change pe of cohesion -Functional, Layer, Communicational, Sequential Procedural, Temporal, Utility www.oseng.com O Lethbridge/Laganiere 2001 Chapter 9: Architecting and designing software 16
© Lethbridge/Laganière 2001 Chapter 9: Architecting and designing software 16 Design Principle 2: Increase cohesion where possible A subsystem or module has high cohesion if it keeps together things that are related to each other, and keeps out other things • This makes the system as a whole easier to understand and change • Type of cohesion: —Functional, Layer, Communicational, Sequential, Procedural, Temporal, Utility
Functional cohesion This is achieved when all the code that computes a particular result is kept together-and everything else is kept out i. e. when a module only performs a single computation, and returns a result, without having side-effects Benefits to the system -Easier to understand more reusable -Easier to replace Modules that update a database create a new file or interact with the user are not functionally cohesive www.oseng.com O Lethbridge/Laganiere 2001 Chapter 9: Architecting and designing software 17
© Lethbridge/Laganière 2001 Chapter 9: Architecting and designing software 17 Functional cohesion This is achieved when all the code that computes a particular result is kept together - and everything else is kept out • i.e. when a module only performs a single computation, and returns a result, without having side-effects. • Benefits to the system: —Easier to understand —More reusable —Easier to replace • Modules that update a database, create a new file or interact with the user are not functionally cohesive
Layer cohesion All the facilities for providing or accessing a set of related services are kept together, and everything else is kept out The layers should form a hierarchy higher layers can access services of lower layers -Lower layers do not access higher layers The set of procedures through which a layer provides its services is the applicationprogramming interface(APl) You can replace a layer without having any impact on the other layers You just replicate the apl www.oseng.com O Lethbridge/Laganiere 2001 Chapter 9: Architecting and designing software 18
© Lethbridge/Laganière 2001 Chapter 9: Architecting and designing software 18 Layer cohesion All the facilities for providing or accessing a set of related services are kept together, and everything else is kept out • The layers should form a hierarchy —Higher layers can access services of lower layers, —Lower layers do not access higher layers • The set of procedures through which a layer provides its services is the application programming interface (API) • You can replace a layer without having any impact on the other layers —You just replicate the API
Example of the use of layers pplication programs Screen displa facilities Dealing with application protocols User account User management Dealing with nterface connections File Application system Dealing with logic ackets Kernel Operating systemDatabase Network (handling processes Transmitting access access communication and swapping) and receIvng a) Typical layers in an b)Typical layers in an c)Simplified view of layers application program operating system In a communication system www.oseng.com O Lethbridge/Laganiere 2001 Chapter 9: Architecting and designing software 19
© Lethbridge/Laganière 2001 Chapter 9: Architecting and designing software 19 Example of the use of layers Screen display facilities User account management File system Kernel (handling processes and swapping) Application programs User interface Application logic Database access Network communication Transmitting and receiving Dealing with packets Dealing with connections Dealing with application protocols a) Typical layers in an application program b) Typical layers in an operating system c) Simplified view of layers in a communication system Operating system access
Communicational cohesion All the modules that access or manipulate certain data are kept together(e.g. in the same class )-and everything else is kept out a class would have good cor cational cohesion -if all the systems facilities for storing and manipulating its data are contained in this class -if the class does not do anything other than manage its data Main advantage: When you need to make changes to the data, you find all the code in one place www.oseng.com O Lethbridge/Laganiere 2001 Chapter 9: Architecting and designing software
© Lethbridge/Laganière 2001 Chapter 9: Architecting and designing software 20 Communicational cohesion All the modules that access or manipulate certain data are kept together (e.g. in the same class) - and everything else is kept out • A class would have good communicational cohesion —if all the system’s facilities for storing and manipulating its data are contained in this class. —if the class does not do anything other than manage its data. • Main advantage: When you need to make changes to the data, you find all the code in one place