Software Design and Architecture Lecture #3
CRC For conceptual design Components Responsibilities Collaborators
Class diagrams for technical design
Class from code
Encapsulation and access modifiers
Decomposition Three types of relationship in decomposition Association Aggregation Composition
Association
Aggregation(Weak “has-a”)
Composition(strong “has-a”)
Generalization Generalization helps reduce redundancy when solving problems. In coding, algorithmic behaviors are often modelled through methods object-oriented modelling achieves generalization by classes through inheritance
Generalization with inheritance
Inheritance
Generalization with interfaces
Coupling Coupling focuses on complexity between a module and other modules If a module is too reliant on other module(s) it is “tightly coupled” other wise “loosley coupled”. Metrics to consider for coupling are Degree(Number of connections to other modules) Ease (How obvious are the connections?) Flexibility(replaceable modules without effecting each other)
Cohesion Cohesion focuses on complexity within a module, and represents the clarity of the responsibilities of a module A module that performs one task and nothing else, or that has a clear purpose, has high cohesion. if a module encapsulates more than one purpose, if an encapsulation has to be broken to understand a method, or if the module has an unclear purpose, it has low cohesion
High or Low cohesion?
Separation of concerns Abstraction occurs as each concept in the problem space is separated with its own relevant attributes and behaviors. Encapsulation occurs as the attributes and behaviors are gathered together into their own section of code called a class. Access to the class from the rest of the system and its implementation are separated, so details of implementation can change while the view through an interface can stay the same. Decomposition occurs as a whole class can be separated into multiple classes. Generalization occurs as commonalities are recognized, and subsequently separated and generalized into a superclass.
Example public class SmartPhone { } private byte camera; private byte phone; public SmartPhone() { … } public void takePhoto() { … } public void savePhoto() { … } public void cameraFlash() { … } public void makePhoneCall() { … } public void encryptOutgoingSound() { … } public void decipherIncomingSound() { … } }
public class SmartPhone { private ICamera myCamera; private IPhone myPhone; public SmartPhone( ICamera aCamera, IPhone aPhone ) { this.myCamera = aCamera; this.myPhone = aPhone; } public void useCamera() { return this.myCamera.takePhoto(); public void usePhone() { return this.myPhone.makePhoneCall();
Information hiding Access Modifiers Public Private Default Protected