8311302 Class Diagram Department of Informatics Faculty of












































































- Slides: 76
8311302 ����� เคราะหและออกแบบเชงวตถ Class Diagram. Department of Informatics Faculty of Science and Technology Phuket Rajabhat University 1/2553 OOAD 1
Outline • • • Structural Modeling Class Diagrams and Object Diagrams Association Generalization ��� Classification Aggregation ��� Composition OOAD 2
Structural Modeling OOAD 3
Structural Modeling: Core Elements OOAD 5
Structural Modeling: Core Elements (cont’d) ¹ An extension mechanism useful for specifying structural elements. OOAD 6
Structural Modeling: Core Relationships OOAD 7
Structural Modeling: Core Relationships (cont’d) OOAD 8
Structural Diagrams • ประเภทของ Structural Diagrams – static structural diagrams • class diagram • object diagram – implementation diagrams • component diagram • deployment diagram OOAD 9
Static Structural Diagrams OOAD 10
Static Structural Diagrams • แสดงกราฟ�������� �� static relationships • ����� Static Structural Diagrams – class diagram : classifier view – object instance diagram : instance view OOAD 11
Classes in UML • ���� 2 ������ Class name Person Attributes attribute name : type Operations operation name(parameter : type) : result type OOAD Person - Tax. IDNo : String - Name : String + Income : double + Tax. Paid : Boolean + calc. Tax() + calc. Tax. Bal() 13
UML Syntax for Attributes • visibility name : type + id : String – visibility: public (+), protected (#), private (-) • การตความไมขนกบ ภาษาทใชเขยนโปรแกรม – name : ���� string – type : �������� OOAD 14
UML syntax for operations • visibility name (parameter list) : return-type-expression + assign. Agent (a : Agent) : Boolean – visibility: public (+), protected (#), private (-) • การตความไมขนกบภาษาทใชเขยนโปรแกร ม – name : string – parameter list : arguments – return-type-expression : ������ return ������� OOAD 15
Objects in UML • ���� 2 ������ Object name Tim: Person Attributes attribute name : type = value Same Operations for all instances of a class OOAD Tim : Person Tax. IDNo=“ 23003” Name=“Tim. Lim” Income=“ 30000. 00” Tax. Paid = FALSE calc. Tax() calc. Tax. Bal() 18
An Object Instance Diagram Sydney: City Name=Sydney Country=Australia Population= 3, 536, 000 London: City Name=London Country=UK Population= 2, 324, 320 New York : City Name=New York Country=USA Population= 5, 734, 012 OOAD 19
Classes and Objects City Name : String = default Country : String = default Population : integer = default set. Name (s : String = deault) set. Population(p : integer = default) <<instance. Of>> London : City New York : City Sydney : City Name = London Country = UK Population =2, 324, 320 Name = New York Country = USA Name = Sydney Country = Australia Population =5, 734, 012 Population =3, 536, 000 OOAD 20
Class Diagrams • • Associations Generalization ��� Classification Aggregation OOAD 21
Association • ความสมพนธ ��� classes (Relationship) ������� instances association name direction Order date. Received is. Prepaid number : String * price : Money Customer issued by 1 dispatch( ) Customer may make several orders name address credit. Rating( ) Order comes from one customer OOAD 22
Naming associations • ������ association – ���������� • associated_with, has, is_related_to – ���������� • works_for, owns , issued by – ���������� Association ����������� diagram OOAD 24
Associations on Class Diagrams Person Name Address Telephone Car Owns OOAD Manufacturer Model Registration 25
Objects & Links You: Person Me: Person Name=Jane Address=22 Holly Pl Telephone=62312198 Name=Dennis Address=41 High St Telephone=62661734 Owns Ours: Car Mine: Car Manufacturer=Mazda Model=626 Registration=YYX 391 Manufacturer=Saab Model=95 Registration=YRT 833 OOAD 27
Association Multiplicity • multiplicity – ����������� instances (objects) ������������������� instance (object) Order ���������� date. Received is. Prepaid number : String price : Money 1 * Customer name address credit. Rating( ) dispatch( ) OOAD 28
Association Multiplicity 1 1. . * Class exactly one Class one or more 0. . 1 * Class many (zero or more) Class zero or one/at most one 2. . 4 Class as specified OOAD 29
Example of Multiplicities Student * * University 1 Body Heart 2 -3 Bicycle * 1. . * Account Wheel 1. . * * * OOAD Owner 30
Associations, Objects & Classes • สำหรบ association ������� 2 �������� link ����� 0 ��� 1 link • ������� 2 ����������� 1 association (Multiple Assoications) ��� association ��������� association • Multiple associations ��������� OOAD 31
Role names • Role ��������� association Company Name Address Works for employer * employee Person Name Insurance no. Address Role names OOAD 33
Role names • ���������� Role ��������� link �������������� Person Manager Supervises Name Insurance no. Address Salesperson OOAD 35
A Reflexive Association • association ��������� Person Name Address Telephone Parent 2 Role name * Child OOAD 36
Ternary Associations Vendor Customer Sale Product Ternary association OOAD 38
Ternary Association Multiplicity • multiplicity ��� ternary associations • ������ binary ��� unary associations • ������� “many” ��������� (participating) OOAD 39
Summary: Basic notation for associations Class A mult 1 Association name role_B mult 2 role_A Class B • ������ Order 1 contains OOAD * line items Order Line 41
Association Classes • Link ������������������ attribute ������ • attribute �������� association class �������������� whenever it exists or has meaning when the link itself exists (rather than just the objects linked) OOAD 42
Association Classes Student ID Name Address Telephone Enrolment * Subject Code * Name Credit Result Mark Association class OOAD 43
Association Classes • association class ������� associations ������������ OOAD 44
Association Classes Customer Name Address Telephone 1. . 0 Claim * Purchase Guarantee Date Length * Conditions OOAD Product * Number Name Price Association class 45
Qualified Associations • qualified association – หมายถง association ��������� attribute ������ qualifier – ������� qualified association ��������� weak entity type �� ER OOAD 46
Qualified Associations Unqualified Golf_Course Name 1 Location Hole Number * Length Par Qualified Golf_Course Name Location Hole 0. . 1 Length Hole. Number 1 Par OOAD 47
Qualified Association Tournament Year Position 0. . 1 OOAD Prize 48
Qualified association Company Function Organization Person * ABC Inc. XYZ Inc. President Vice President Finances Member of board President OOAD Roger Rabbit Joe Savemoney John Walker Susi Sanssouci Karl Eichbaum Donald Duck 49
Difference between attributes and associations • Conceptual perspective – ��������� – Attributes ������ (single-valued) • Specification/implementation perspective – Attribute ������� (Value) �������� (References) • ไมมการ share ������� attribute values ����� instances �������� OOAD 51
Class diagrams (cont. ) • • Associations Generalization ��� Classification Aggregation OOAD 52
Generalization • ��������� – Generalization ������ classes ��������� (class Hierarchy) ������� similarities ��� differences – ��������� classes hierarchy ��� “superclasses” ��������� “subclasses” OOAD 53
Inheritance and Polymorphism • “subclass” �������� (inherits)����� attributes, operations ��� associations ����� “superclass” ����� • �������� ��� attribute ���� operation ��� “superclass” ���� ���� “subclass” ����� “overrides” คำนยามทกำหนดไวใน “superclass” OOAD 54
Superclasses and Subclasses • “Superclass” ����� attributes, operations ��� associations ����� “subclasses” ������ • “Subclasses” �� attributes, operations ��� associations ������������������ attribute, operation ���� relationship ������ “superclass” ������ OOAD 55
A Generalization Hierarchy Superclass Ellipse Major_Axis Minor_Axis Geometric_Figure X_Position Y_Position Circle Radius Rectangle Width Height Subclasses OOAD 56
Single & Multiple Inheritance • generalizations ����� class hierarchies ���� “subclass” ������� 1 “superclass” ���� “single inheritance” • แตมบางสถานการณท “subclass” �������� 1 “superclass” ���� “multiple inheritance” OOAD 57
Multiple Inheritance Employee General. Staff Prof. Staff Full. Time Academic OOAD Part. Time Subclass with two superclasses 58
Multiple Inheritance Vehicle Furniture Wheelchair OOAD 59
Class diagrams (cont. ) • • Associations Generalization ��� Classification Aggregation OOAD 61
Generalization and Classification (= is_a? ) 1. Shep is a Border Collie. 2. A Border Collie is a Dog. 3. Dogs are Animals 4. A Border Collie is a Breed. 5. Dog is a Species 1+2: Shep is a Dog 1+2+3: Shep is a animal 1+4: Shep is a breed? ? ? 2+5: A Border Collie is a Species? ? ? Generalization is transitive (is kind of) Classification is not transitive (is instance of) OOAD 62
Class diagrams (cont. ) • • Associations Generalization ��� Classification Aggregation OOAD 63
Notation for aggregation Class A ���� Class B Class C OOAD 65
Example : Aggregation 1 Title Aggregation * Chapter Front 1 1 1 Book 1 0. . 1 Preface 0. . 1 End * Appendix OOAD 1 1 0. . 1 Index 66
Example : Aggregation Company * Unit * Department * Group works for * Employee OOAD 67
Aggregation and composition Polygon Aggregation 1 1 Composition 1 Graphics Bundle 3. . * color texture Point OOAD 70
Association and Aggregation • Question : Association ���� Aggregation? • Answer : ���� Aggregation – ถาความสมพนธเปน “part of” – Operation ����������������� OOAD 71
Generalization and Aggregation • Question : Generalization ���� Aggregation ? • Answer : ���� Generalization – ถาความสมพนธเปน “kind of” – ��������� “or” • Answer : ���� Aggregation – ถาความสมพนธเปน “part of” – ��������� “and” OOAD 72
Class Diagram - Example • • A zoo consists of a set of cages. Every cage is the home of at least 2 animals. Cages are located besides each other. Every cage has at most one left neighbor and at most one right neighbor. Animals can be reptiles, insects, and mammals. Mammals are elephants, monkeys, and tigers. Monkeys eat bananas. Tigers prefer meat. OOAD 73
Class Diagram Schedule. Algorithm Registration. Form Registration. Manager add. Student(Course, Student. Info) name number. Credits open() add. Student(Student. Info) Student name major Professor name tenure. Status Course. Offering location open() add. Student(Student. Info) OOAD 74
Class Diagram: Notation Summary (stereotype) Classname {abstract} signature attribute: Type $class_attribute: Type = Default_value 1 Association_name {constraint} operation {abstract} operation (arg 1: Type): Type $class_operation discriminators Composite. Classname * attribute: Type Role_name operation Qualifier Association Classname association_attrib: Type Sub. Classname 1 Sub. Classname 2 attribute: Type operation OOAD Component. Classname attribute: Type operation 75
Class Diagram: Notation Summary (cont’d) formal_arg Parameterised Instantiated Class. Name Instantiates Class. Name<actual_arg> Class. Name 1{constraint} Uitlity attribute: Type operation(arg: Type): Type Class. Name 2 Class. Name 3 Category. Name inheritance association instantiation has by-value + # null / public protected private unspecified derived has by-reference ternary Sub. Category 1 dependency Class. Name: access Sub. Category 2 Category. Name (Public Interface) Class. Name: access Notes OOAD 76