100 likes | 211 Views
Object-Oriented Design and Class Diagrams. OO Design. Planning the components (classes) necessary for a system Determine: the classes that will be defined their roles and relationships (and interaction) with each other Modeling. Why Go Through Design?.
E N D
OO Design • Planning the components (classes) necessary for a system • Determine: • the classes that will be defined • their roles and relationships (and interaction) with each other • Modeling
Why Go Through Design? • Modeling a system before implementing (coding) saves time and increases the chances of success • Can worry less about programming details • The design model serves as a coordination point between programmers in a team
Modeling Techniques • Notation • The UML: Unified Modeling Language • The Standard for OO Systems • Diagramming Techniques in the UML • Class Diagrams • Use Cases • Interaction Diagrams • Others
Class Diagrams • What is Depicted? • Classes • name, attributes, methods • rectangles • Relationships • inheritance, composition, association • links
Classes in a Class Diagram • Class name only Example • With Details Example Ledger Class Name Ledger double balance post() sortByDate() Class Name attributes methods
Relationships • Inheritance (arrow) • example: between Secretary and Employee • Composition/Aggregation (diamond) • example: between Car and Wheel • Association (line) • example: between Borrower and Book
Inheritance Employee public class Secretary extends Employee { … } Secretary
Composition Car Wheel 4 w[] public class Car { Wheel w[]; ... public Wheel() { w = new Wheel[4]; … } ... }
Association Borrower Book 1 3 currBorr bk[] public class Borrower { Book bk[]; … public Borrower() { bk = new Book[3]; } } public class Book { Borrower currBorr; … }