Software Design and Architecture Lecture 3 CRC For
























- Slides: 24
 
	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 Smart. Phone { private byte camera; private byte phone; public Smart. Phone() { … } public void take. Photo() { … } public void save. Photo() { … } public void camera. Flash() { … } public void make. Phone. Call() { … } public void encrypt. Outgoing. Sound() { … } public void decipher. Incoming. Sound() { … } }
 
	
	 
	public class Smart. Phone { private ICamera my. Camera; private IPhone my. Phone; public Smart. Phone( ICamera a. Camera, IPhone a. Phone ) { this. my. Camera = a. Camera; this. my. Phone = a. Phone; } public void use. Camera() { return this. my. Camera. take. Photo(); } public void use. Phone() { return this. my. Phone. make. Phone. Call(); } }
 
	Information hiding • Access Modifiers • • Public Private Default Protected
 
	
	