Professional Documents
Culture Documents
Cours 3 - Classes Structurées Et Collaborations
Cours 3 - Classes Structurées Et Collaborations
Conception Orientée Objets
Classes Structurées et
Collaborations
Frédéric Mallet
http://deptinfo.unice.fr/~fmallet/
F. Mallet ‐ COO 1
Classes Structurées et Collaborations
Classes are grouped within Packages
Registration
CloseRegistrationForm CloseRegistrationController
RegisterForCoursesForm RegistrationController
F. Mallet ‐ COO 2
Classes Structurées et Collaborations
Associations
The semantic relationship between two or more
classifiers that specifies connections among their
instances.
A structural relationship specifying that objects of one
thing are connected to objects of another thing.
How to decide which associations? Which methods?
F. Mallet ‐ COO 3
Classes Structurées et Collaborations
Use interactions to find associations
1: submit schedule( ) 2: submit schedule( )
: RegisterForCoursesForm : RegistrationController
: Student
8: any conflicts?( )
3: save( )
4: submit( )
6: has pre-requisites(CourseOffering)
: CourseOffering
: Student
5: is selected?( )
10: mark as enrolled in( )
: PrimaryScheduleOfferingInfo
F. Mallet ‐ COO 4
Classes Structurées et Collaborations
Structural Diagrams
Static view of a system
CloseRegistrationForm Schedule CloseRegistrationController
- semester
+ open() + is registration open?()
+ close registration() + commit() + close registration()
+ select alternate()
+ remove offering()
+ level() Professor
+ cancel() - name
Student + get cost() - employeeID : UniqueId
+ delete() - hireDate
+ submit() - status
+ get tuition()
+ save() - discipline
+ add schedule()
+ any conflicts?() - maxLoad
+ get schedule()
+ create with offerings()
+ delete schedule()
+ update with new selections() + submitFinalGrade()
+ has pre-requisites()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
+ teachClass()
F. Mallet ‐ COO 5
Classes Structurées et Collaborations
Generalization
A relationship among classes where one class shares
the structure and/or behavior of one or more
classes.
Defines a hierarchy of abstractions where a subclass
inherits from one or more super classes.
Single inheritance
Multiple inheritance
Is an “is a kind of” relationship.
F. Mallet ‐ COO 6
Classes Structurées et Collaborations
Example: Single Inheritance
One class inherits from another.
Ancestor
Account
- balance
Superclass - name
(parent) - number
+ withdraw()
+ createStatement()
Generalization
Relationship
Subclasses
Savings Checking
(children)
Descendents
F. Mallet ‐ COO 7
Classes Structurées et Collaborations
Example: Multiple Inheritance
A class can inherit from several other classes.
FlyingThing Animal
Multiple Inheritance
F. Mallet ‐ COO 8
Classes Structurées et Collaborations
Multiplicity
Multiplicity is the number of instances one class relates to ONE
instance of another class.
For each association, there are two multiplicity decisions to make,
one for each end of the association.
For each instance of Professor, many Course Offerings may be taught.
For each instance of Course Offering, there may be either one or zero
Professor as the instructor.
instructor
Professor CourseOffering
0..1 0..*
F. Mallet ‐ COO 9
Classes Structurées et Collaborations
Complex Associations
Ternary association
Association Classes
F. Mallet ‐ COO 10
Classes Structurées et Collaborations
Complex Associations
Qualified Associations
F. Mallet ‐ COO 11
Classes Structurées et Collaborations
Aggregation
A special form of association that models a whole‐part
relationship between the aggregate (the whole) and its
parts.
An aggregation is an “is a part‐of” relationship.
Multiplicity is represented like other associations.
Whole 1 Part
0..1
F. Mallet ‐ COO 12
Classes Structurées et Collaborations
Composition
A special form of aggregation where the composite (the
whole) is responsible for the existence of the parts
An aggregation is an “owns” relationship
Composition is more restricting than aggregation
Parts (instances) are not shared
E.g., A wheel is not shared between two cars
Car Wheel
F. Mallet ‐ COO 13
Classes Structurées et Collaborations
Composite Structure
Richer and more precise way to express composition
Can also express aggregation (dashed lines)
Warning: Parts are Properties, not instances
Car
4 Wheel a : Axle
Engine
2
Parts
F. Mallet ‐ COO 14
Classes Structurées et Collaborations
Structured classifiers
Show roles of parts
Parts ARE NOT instances
Car
: Engine
frontRight : rearRight :
Wheel Wheel
F. Mallet ‐ COO 15
Classes Structurées et Collaborations
Instance of a structured classifiers
Show roles of parts
Instance parts have
• An instance name, a role and a type (optional)
mycar : Car
: Engine type
energy2 / energy4 /
frontRight : rearRight :
Wheel Wheel
F. Mallet ‐ COO 16
Classes Structurées et Collaborations
Structured Classifiers
Metamodel
F. Mallet ‐ COO 17
Classes Structurées et Collaborations
Connectors and Ports
Provided & Required Interfaces
F. Mallet ‐ COO 18
Classes Structurées et Collaborations
COLLABORATIONS
F. Mallet ‐ COO 19
Classes Structurées et Collaborations
Collaborations
Semantics
How a system of communicating elements collectively
accomplish a specific task or set of tasks (pattern)
Metamodel
F. Mallet ‐ COO 20
Classes Structurées et Collaborations
Example
Collaboration
« collaboration »
Sale
Buyer Seller
CollaborationUse
F. Mallet ‐ COO 21