Object and class relationships
-
Upload
pooja-mittal -
Category
Engineering
-
view
272 -
download
1
Transcript of Object and class relationships
![Page 1: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/1.jpg)
![Page 2: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/2.jpg)
2
A CLASS is a template (specification, blueprint)for a collection of objects that share a commonset of attributes and operations. Health Club Member
Class
Objects
attributesoperations
Defining Class
![Page 3: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/3.jpg)
UML Class Diagrams 3
What is a Class Diagram?
•A Class Diagram is a diagram describing the structure of a system shows the system's •classes•Attributes•operations (or methods),•Relationships among the classes.
![Page 4: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/4.jpg)
4
1 of 2
UML Class Diagram Notation
Class
Member
memberNumberfirstNamelastNametelephoneaddresscityetc...
checkOutVideocheckInVideobuyItemetc...
attributes
operations
{{
Expanded view of a
Class into its three
sections:
Top: Class Name
Middle: attributes
Bottom: operations
![Page 5: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/5.jpg)
5
2 of 2
Object Association
n n
ClassGeneralizationRelationship
ObjectAggregationAssociation
0..*
1..*
Object CompositionAssociation
0..*
1
Will always be “1”
UML Class Diagram Notation
![Page 6: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/6.jpg)
UML Class Diagrams 6
Essential Elements of a UML Class DiagramClassAttributesOperationsRelationships
![Page 7: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/7.jpg)
7
AssociationAggregation/CompostionDependencies Generalization Realization
![Page 8: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/8.jpg)
8
AssociationsAn association between two classes describes connection among them.If the association is between two classes then it is called binary association.There can be association among more than two classes.It is represented by a solid line.Example: “An Employee works for a Company”
Employee Company
![Page 9: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/9.jpg)
9
Class A Class Brole A
role B
Company PersonEmployer
Employee
Example:
Associations
![Page 10: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/10.jpg)
10
Aggregation & Composition•Aggregation (shared aggregation):
• is a specialized form of ASSOCIATION in which a whole is related to its part(s).• is known as a “part of” or containment relationship and follows the “has a” heuristic• three ways to think about aggregations:
• whole-parts• container-contents• group-members
• Composition (composite aggregation):• is a stronger version of AGGREGATION• the “part(s)” may belong to only ONE whole• the part(s) are usually expected to “live” and “die” with the whole (“cascading delete”)
• Aggregation vs. Composition vs. Association???
![Page 11: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/11.jpg)
11
Aggregation Composition
0..*
1..*
Faculty
CourseTeaching
1..*
1
SalesOrder
SalesOrderLineItem
(another: hand --> finger)(another: assembly --> part)
(team-teaching is possible)
![Page 12: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/12.jpg)
12
Generalization• Deriving a class out of a parent class having
some inherited property(from the parent class) and some new property of the derived class.
• The term generalization is for the inheritance in the bottom to the up direction i.e. from derived class to the parent class.
![Page 13: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/13.jpg)
• It is represented by a solid line with a large arrow head pointing towards the parent class.
• Example:
13
Vehicle
Car Truck
![Page 14: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/14.jpg)
14
Dependency• A dependency relationship is a weaker form
of relationship. A dependency states that a change in specification of one class may effect another class that uses first one but not vice versa.
• It is represented by dashed lines.
Dependent class Reference class
![Page 15: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/15.jpg)
15
Realization • Realization is very similar to
inheritance ,the only difference between them is a class is derived from an interface instead of a base class.
• An interface is an abstract class.
Interface class Derived class
![Page 16: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/16.jpg)
16
![Page 17: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/17.jpg)
UML Class Diagrams 17
![Page 18: Object and class relationships](https://reader034.fdocuments.in/reader034/viewer/2022050723/55905ab01a28ab84208b45cc/html5/thumbnails/18.jpg)
UML Class Diagrams 18