170 likes | 307 Views
Class Diagrams. Perspectives. Conceptual classes represent concepts in a domain software (& language) independent Specification classes represent interfaces (or types) Implementation full classes automatic code generation. Interface vs Implementation.
E N D
Class Diagrams Class Diagrams
Perspectives • Conceptual • classes represent concepts in a domain • software (& language) independent • Specification • classes represent interfaces (or types) • Implementation • full classes • automatic code generation Class Diagrams
Interface vs Implementation • Not well distinguished by current OOP languages • Classes (particularly in C++) combine the two • Design Rule #1 • Program to the interface, not the implementation Class Diagrams
A Class Diagram Class Diagrams
A Class Diagram Associations Class Diagrams
Associations • Relationships between instances of classes • Conceptual perspective conceptual relation • Specification perspective responsibility • Implementation imply specifics (e.g. pointers) Associations Class Diagrams
A Class Diagram Generalization Class Diagrams
A Class Diagram Abstract class represented by italicised name Class Diagrams
Multiplicities • Mandatory • At each end • 0..1 • 0..* • 1..* • 1,3,9..11 Multiplicities Class Diagrams
Multiplicities Class Diagrams
Role Names Role Names Class Diagrams
Role Names • Are optional • May go at either (or both) end(s) • Alternatively, association itself may be named • Bleah! • Only name roles when it adds clarity Class Diagrams
Role Names Role Names Class Diagrams
Multiple associations Second association saying department has one head who is a professor (and prof can only be head of one department) Class Diagrams
Directed associations New association is directed, meaning it can only be navigated from department to prof. E.g. department is supposed to know who its head is but prof doesn't have to know he/she is head. Class Diagrams
Direction • No arrowheads means either • directionality is unspecified • navigability is in both directions • I prefer unspecified (except, perhaps in implementation perspective) Class Diagrams
Attributes • What is difference between attribute and association? • Often none • At implementation, association will often imply a pointer from one class to the other • Use attributes for primitive, wholly contained data (integers, strings) Class Diagrams