Object Oriented System Design Lecture7 and 8 Introduction
Object Oriented System Design Lecture-7 and 8 Introduction to Class Diagram Hari Mohan Pandey Department of Computer Science & Engineering ASET, Amity University hmpandey@amity. edu 1
Session Objective Upon completion of this session students will be able to define and use the following: 1. Class Diagram 2. Implementation of Class Diagram 4. Advantages of Class Diagram 3. Application of Class Diagram 2
Introduction: Class Diagram • Class diagrams model class structure • Class diagram uses design elements such as: Ø Classes, Ø Packages and Ø Objects. • A class diagram is a diagram showing a collection of classes and interfaces. • Class diagrams are static -- they display what interacts but not what happens when they do interact. 3
Class Diagram: Example-1 • Example: Let us take a class named Student. • The Student class encapsulates (attributes) such as – student id #, – student name, etc. student information • The Student class also exposes functionality to other classes by using methods such as § get. Student. Name(), § get. Student. Id(), etc. . 4
Class Diagram: Example-1 Cont. • The following diagram shows the class diagram for student class. 5
Class diagrams-Example-2 • The class diagram shown models a customer order from a retail catalog. • The central class is the Order. • Associated with it are the Customer making the purchase and the Payment. • A Payment is one of three kinds: Cash, Check, or Credit. • The order contains Order. Details (line items), each with its associated Item. 6
Class diagrams-Example-2 Cont. 7
Association • What? : Association is a relationship between instances of the two classes. • When? : There is an association between two classes if an instance of one class must know about the other in order to perform its work. • How? In a diagram, an association is a link connecting two classes. • An association has two ends. • An end may have a role name to clarify the nature of the association. • For example, an Order. Detail is a line item of each Order. 8
Association Cont. • A navigability arrow on an association shows which direction the association can be traversed or queried. • An Order. Detail can be queried about its Item, but not the other way around. • The arrow also lets you know who "owns" the association's implementation; in this case, Order. Detail has an Item. • Associations with no navigability arrows are bi-directional. 9
Association Cont. • The multiplicity of an association end is the number of possible instances of the class associated with a single instance of the other end. • Multiplicities are single numbers or ranges of numbers. • In our example, there can be only one Customer for each Order, but a Customer can have any number of Orders. 10
Association Cont. Multiplicities Meaning 0. . 1 zero or one instance. The notation n. . m indicates n to m instances. 0. . * or * no limit on the number of instances (including none). 1 exactly one instance 1. . * at least one instance 11
Aggregation • An association in which one class belongs to a collection. • An aggregation has a diamond end pointing to the part containing the whole. • In our diagram, Order has a collection of Order. Details. 12
Aggregation: Example-3 13
Aggregation: Example-4 14
Generalization • An inheritance link indicating one class is a superclass of the other. • A generalization has a triangle pointing to the superclass. • Payment is a superclass of Cash, Check, and Credit. 15
Generalization: Example-5 16
Class Aggregation 18
Middle East College of Information Technology, Muscat, Oman 19
Example-6 • We have customers who order our products. • We distinguish corporate customers from personal customers, since corporate customers are billed monthly whereas personal customers need to prepay their orders. • We want our orders to be lined up product by product. • Each line should contain the amount and the price of each product 20
21
22
23
24
25
Example-7: Use Case 26
Example- Class Diagram 27
Introduction: Object Diagram • Object diagrams show instances instead of classes. • They are useful for explaining small pieces with complicated relationships, especially recursive relationships. • Each rectangle in the object diagram corresponds to a single instance. • Instance names are underlined in UML diagrams. • Class or instance names may be omitted from object diagrams as long as the diagram meaning is still clear. 28
Object Diagram: Example-8 29
Object Diagram: Example-9 30
Object Diagram: Example-10 31
Object Diagram: Example-11 32
Summary/Conclusion • In this session we studied about a) Class Diagram b) Advantages of Class Diagram c) Class Diagram Relationships d) Examples to show the implementations e) We also studied about object diagram and f) Implementation of object diagrams 33
Thank You!!! 34
- Slides: 34