Professional Documents
Culture Documents
and Architecture
CONCEPTS OF COHESION AND COUPLING
Inheritance Coupling
description
serviceDate
LandVehicle AirVehicle
numberOfAxles maximumAltitude
registrationDate takeOffSpeed
checkAltitude()
register()
takeOff()
3
Principle of Decoupling
Lecturer
lecturerName
lecturerAddress
roomNumber
roomLength
roomWidth {return
roomLenght*
calculateRoomSpace()
roomWidth;}
Poor Specialization Cohesion
number
street
town
county
country
postCode
Person Company
personName companyName
age annualIncome
gender annualProfit
Improved Structure
Address
number
street
town
county
country
postCode
lives at is based at
Person Company
personName companyName
age annualIncome
gender annualProfit
8
GraphicDisplaySystem GraphicDisplaySystem
• Less dependency
-drawCicle() +drawShapes() • Easy expansion
-drawRectange()
-drawTriangle() • Simplicity and
+drawShapes()
elegancy in
implementation
Shape Shape
+draw()
Promote Cohesion
Professor
-studentRecords : object
RegistrarOffice Student
-courseMaterials : object
+prepareGradApp() : object
-verifyDegree() : object
-adviseCurriculum() : object
AppForGraduation +getLectureNotes() : object StudentRecords
+getAssignment() : object
Improved Design
«interface»
«interface»
Instructor
Advisor
+getLectureNotes() : object
+prepareGradApp() : object
+getAssignments() : object
Professor
-studentRecords : object
-courseMaterials : object
RegistrarOffice +prepareGradApp() : object Student
-verifyDegree() : object
-adviseCurriculum() : object
AppForGraduation +getLectureNotes() : object StudentRecords
+getAssignment() : object
CourseMate
Assignment LectureNote
rials
Liskov Substitution Principle
MortgageAccount
MortgageAccount ChequeAccount
interestRate
interestRate
calculateInterest() debit()
- debit() calculateInterest()
15
Open-Closed Principle
Open to Extension
The system can be extended to meet new requirements
Close to Modification
The existing implementation should not be modified
How to do it?
Inheritance and polymorphism
16
Example
GraphicDisplaySystem GraphicDisplaySystem
-drawCicle() +drawShapes()
-drawRectange()
-drawTriangle()
+drawShapes()
Shape Shape
+draw()
Implications
Summary
Concepts of Coupling
Concepts of Cohesion