60 likes | 77 Views
Explore the fundamentals of UML class diagrams, a key component of Unified Modeling Language (UML) for designing object-oriented software systems. Learn about relationships, details of classes, multiplicities, and inheritance concepts. Understand how to depict attributes, operations, and relationships for effective software design.
E N D
UML class diagrams: What are they? • Unified Modeling Language (UML) • “A family of graphical notations … that help in describing and designing [object-oriented] software systems” – Martin Fowler • Developed in 1997 to unify the previous object-oriented graphical modeling languages • Now the world-wide standard • We focus on UML class diagrams • These show: • Relationships between classes in the software system • Details of the classes
1 means one * means 0 or more 1 .. * means 1 or more 0 .. 1 means 0 or 1 A relationships-onlyUML class diagram • is-a (by extending a class) • is-a (by implementing an interface) • has-a Person * * Man Woman Daughter Son 1 1 This diagram might also show which objects are to construct which other objects Father Mother PersonAbleToProcreate <<interface>>
A relationships-onlyUML class diagram Instructor: give each student a paper copy of this slide. The example is taken from Martin Fowler’s UML Distilled, 3rd Edition. Exercise: draw arrows to indicate the relationships between these classes in an order-processing system. For example, think of the company as Amazon and the system as Amazon’s system for processing orders from customers. After drawing the arrows, indicate the multiplicities. Order Customer lineItem Order Line Corporate Customer Personal Customer Product 1 means one * means 0 or more 1 .. * means 1 or more 0 .. 1 means 0 or 1 is-a (by extending a class) is-a (by implementing an interface) has-a salesRep Employee
A relationships-onlyUML class diagram Instructor: give each student a paper copy of this slide. The example is taken from Martin Fowler’s UML Distilled, 3rd Edition. Exercise: draw arrows to indicate the relationships between these classes in an order-processing system. For example, think of the company as Amazon and the system as Amazon’s system for processing orders from customers. Here is one answer, but not the only possible one! Depends on exactly what you want to model… Order Customer * 1 1 lineItem * Order Line * Corporate Customer Personal Customer 1 Product * 1 means one * means 0 or more 1 .. * means 1 or more 0 .. 1 means 0 or 1 is-a (by extending a class) is-a (by implementing an interface) has-a 0..1 salesRep Employee
EyeBall eyeBallColor : Color xPosition : int yPosition : int Radius : int Moves the EyeBallto follow the mouseto the given point draw( Graphics) look(int, int) Fields-and-methods UML class diagram with details • Together, let’s examine JavaEyes and fill in the details for the EyeBall class in the UML class diagram • What are the attributes? Their types? • Any comments needed? • What are the operations? Their types? • Any comments needed? • There are two ways to show an object-type attribute: • Draw a HAS-A arrow to it • List it in the detailed box • Choose the former if you want to emphasize the relationship
UML class diagrams • What they are and why use them • A notation to assist object-oriented design (not just Java) • The notations for (see example on handout and on next slide): • Relationships-only class diagram • Generalization: X extends Y (the is-a relationship) • Association: X knows one or more Ys (the has-a relationship) • Multiplicity • Fields-and-methods class diagram • Class name, Fields (attributes), Methods (operations) • Fields-and-methods class diagram with details • This shows the types of the things • How to use them • Design is an iterative process! • Relationships-only, fields-and-methods, iterate, eventually with details