170 likes | 325 Vues
Class diagrams are essential in object-oriented design, representing the structure and relationships within a system. They can be viewed from conceptual, specification, and implementation perspectives. Class diagrams illustrate concepts via classes, showcasing attributes, associations, and multiplicities. It's crucial to differentiate between interfaces and implementations, following the principle of programming to the interface. Associations represent relationships between classes, while multiplicities define the number of instances involved. Understanding these elements enhances the clarity and functionality of your software design.
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