Why Cohesion?

Designing and Maintaining Software (DAMS)
 Louis Rose

Habitable Software Leaner

Avoids Duplication

Less Complex

Clearer

Loosely Coupled

More Extensible

More Cohesive

???

Cohesion

“A measure of the degree to which the
 elements of a module belong together.” - Yourdon & Constantine 
 Structured Design, 1979

Low Cohesion

http://www.housebyhoff.com/2013/01/organizing-our-home-junk-drawer/

High Cohesion

http://www.housebyhoff.com/2013/01/organizing-our-home-junk-drawer/

Cohesion

“A measure of the degree to which the
 elements of a module belong together.” - Yourdon & Constantine 
 Structured Design, 1979

Modular Decomposition “We have tried to demonstrate that it is almost always incorrect to begin the decomposition of a system into modules on the basis of a flowchart. We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others.” - David L. Parnas
 On the Criteria To Be Used in Decomposing Systems into Modules
 Communications of the ACM, 15:12, 1972

Single Responsibility Principle

A class should have only one reason to change. - Martin and Martin
 Chapter 8, Agile Principles, Patterns and Practices in C#, Prentice Hall, 2009

Responsibilities Example Geometry Calculator

<>

Rectangle draw() area()

<>

Graphical Application

<>

GUI Framework

Geometry Calculator

<>

Rectangle area()

<>

RectangleRenderer draw() <>

GUI Framework

<>

Graphical Application

Don’t speculate

A reason for change is only important
 if that change actually occurs.

Reworded SRP

Gather together the things that change for the same reasons. Separate those things that change for different reasons. http://blog.8thlight.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html

Summary Cohesion is a measure of the degree to which
 elements belong together. Following Parnas (and later Martin), elements
 belong together only when they change together

Designing and Maintaining Software (DAMS) - GitHub

“We have tried to demonstrate that it is almost always incorrect to begin the decomposition of a system into modules on the basis of a flowchart. We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision ...

394KB Sizes 0 Downloads 95 Views

Recommend Documents

Designing and Maintaining Software (DAMS) - GitHub
ASTs are tree data structures that can be analysed for meaning (following JLJ in SYAC 2014/15) ... More Cohesive. Avoids Duplication. Clearer. More Extensible.

Designing and Maintaining Software (DAMS) - GitHub
%w.rack tilt date INT TERM..map{|l|trap(l){$r.stop}rescue require l};. $u=Date;$z=($u.new.year + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick". $n=Module.new{extend. Rack;a,D,S,q=Rack

Designing and Maintaining Software (DAMS) - GitHub
Clear Documentation. Designing and Maintaining Software (DAMS). Louis Rose. Page 2. Bad documentation. Misleading or contradictory find_customer(id). CustomerGateway. Used to look up a customer by their customer number. Page 3. Bad documentation. Red

Designing and Maintaining Software (DAMS) - GitHub
R&D: sketch habitable solutions on paper, using UML. 4. Evaluate solutions and implement the best, using TDD. Probably start again at 3. 5. Give to the product owner to validate. Probably start again at 1. 6. Put into production for customers to eval

Designing and Maintaining Software (DAMS) - GitHub
Observers. Designing and Maintaining Software (DAMS). Louis Rose. Page 2. Page 3. Delivery people need to know when pizzas are ready class Pizza def initialize(delivery_person). @delivery_person = delivery_person end def bake cook # blocking call. @d

Designing and Maintaining Software (DAMS) - GitHub
When we are testing the way that a unit behaves when a condition is met, use a stub to setup the condition. Solution: use stubs for queries class Subscription ... def bill(amount) unless payments.exists(subscription_id: id) payments.charge(subscripti