object and class relationships
TRANSCRIPT
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
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.
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
5
2 of 2
Object Association
n n
ClassGeneralizationRelationship
ObjectAggregationAssociation
0..*
1..*
Object CompositionAssociation
0..*
1
Will always be “1”
UML Class Diagram Notation
UML Class Diagrams 6
Essential Elements of a UML Class DiagramClassAttributesOperationsRelationships
7
AssociationAggregation/CompostionDependencies Generalization Realization
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
9
Class A Class Brole A
role B
Company PersonEmployer
Employee
Example:
Associations
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???
11
Aggregation Composition
0..*
1..*
Faculty
CourseTeaching
1..*
1
SalesOrder
SalesOrderLineItem
(another: hand --> finger)(another: assembly --> part)
(team-teaching is possible)
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.
• It is represented by a solid line with a large arrow head pointing towards the parent class.
• Example:
13
Vehicle
Car Truck
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
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
16
UML Class Diagrams 17
UML Class Diagrams 18