Professional Documents
Culture Documents
01b OOPReview
01b OOPReview
Review:
Object-Oriented Programming
Assoc. Prof. TRAN Minh Triet
Department of Software Engineering
References
Private
operations
Public Protected
operations operations
3
How Is Visibility Noted?
Class1
- privateAttribute
+ publicAttribute
# protectedAttribute
- privateOperation ()
+ publicOPeration ()
# protecteOperation ()
4
Scope
Class1
- classifierScopeAttr
- instanceScopeAttr
+ classifierScopeOp ()
+ instanceScopeOp ()
5
Example: Scope
Student
- name
- address
- studentID
- nextAvailID : int
6
Example: Define Operations
<<Interface>>
RegistrationController 0..* ICourseCatalogSystem
1
+ submitSchedule() + getCourseOfferings()
+ saveSchedule() + initialize()
+ getCourseOfferings() : CourseOfferingList
+ getCurrentSchedule ( [in] forStudent : Student, [in] forSemester : Semester) : Schedule
+ deleteCurrentSchedule()
+ new ( [in] forStudentID : String)
+ getStudent ( [in] anID : int) : Student
0..1
+ registrant 0..1
Student
+ getTuition() : double
+ addSchedule ( [in] aSchedule : Schedule)
+ getSchedule ( [in] forSemester : Semester) : Schedule
+ deleteSchedule ( [in] forSemester : Semester)
+ hasPrerequisites ( [in] forCourseOffering : CourseOffering) : boolean
# hasPassed ( [in] aCourseOffering : CourseOffering) : boolean
+ getNextAvailID() : int
+ getStudentID() : int
+ getName() : String
+ getAddress() : String
7
More Notations…
8
Define Associations
❖ Purpose
Refine remaining associations
Navigability
Multiplicity design
9
What Is an Association?
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
10
What Is Aggregation?
Whole/aggregate Part
11
Association or Aggregation?
Car Door
1 0..2,4
❖ If two objects are usually considered as independent, although they
are often linked
The relationship is an association.
Car Door
1 0..2,4
12
What Is Composition?
Whole Part
Whole Part
Composition
13
Aggregation: Shared vs. Non-shared
❖ Shared Aggregation
Multiplicity > 1
❖ Non-shared Aggregation
Multiplicity = 1 Multiplicity = 1
Composition
By definition, composition is non-shared aggregation.
14
Aggregation or Composition?
❖ Consideration
Lifetimes of Class1 and Class2
Class1 Class2
Aggregation
Class1 Class2
Composition
15
Example: Composition
1
Student Schedule
0..*
1
RegisterForCoursesForm RegistrationController
1
16
Attributes vs. Composition
17
Example: Attributes vs. Composition
Attribute
Student
Schedule
- name
- address - semester : Semester
- nextAvailID : int
1 + submit ()
- StudentID : int
- dateofBirth : Date + //save ()
0..*
# any conflicts? ()
+ addSchedule () + //create with offerings ()
+ getSchedule () + new ()
+ delete Schedule () Composition of + passed ()
+ hasPrerequisites () separate class
# hasPassed ()
18
Review: What Is Navigability?
<<Control>>
RegistrationController
Schedule CourseOffering
19
Navigability: Which Directions Are Needed?
0..* 0..4
?
Schedule + primaryCourses CourseOffering Schedule + primaryCourses CourseOffering
20
Example: Navigability Refinement
❖ Total number of
CourseOfferings is small, or
Schedule + primaryCourses CourseOffering
❖ Never need a list of
CourseOfferings on a 0..* 0..4
Schedule
❖ Total number of
CourseOfferings and Schedule + primaryCourses CourseOffering
Schedules are not small 0..* 0..4
❖ Must be able to navigate in
both directions
21
Association Class
<<entity>>
❖ A class is “attached” to an ScheduleOfferingInfo
- status
association
+ // is selected ()
❖ Contains properties of a + // mark as selected ()
+ // mark as cancelled ()
relationship
❖ Has one instance per link
0..* + alternateCourses 0..2
Schedule CourseOffering
0..* + primaryCourses 0..4
<<entity>>
PrimaryScheduleOfferingInfo
- grade
+ // is enrolled in? ()
+ // mark as enrolled in ()
+ // mark as committed ()
22
What Are Roles?
Role Name
<<entity>>
Course
Prerequisites
23
Example: Association Class Design
PrimaryScheduleOfferingInfo
- grade
+ // is enrolled in? ()
+ // mark as enrolled in ()
+ // mark as committed ()
Design Decisions
1
1
- theCourseOffering 0..*
0..4
- primaryCourseOfferingInfo PrimaryScheduleOfferingInfo
- grade
+ // is enrolled in? ()
+ // mark as enrolled in ()
+ // mark as committed ()
24
Multiplicity Design
❖ Multiplicity > 1
Cannot use a simple value or pointer
Further “design” may be required
Needs a
Professor 0..1 0..* CourseOffering
container for
+ Instructor
CourseOfferings
25
Multiplicity Design Options
+ Instructor
26
Multiplicity Design: Optionality
27
What Does Multiplicity Mean?
<<entity>> <<entity>>
0..* 1
CourseOffering Course
0..*
Prerequisites 0..3
28
Define Dependency
❖ What Is a Dependency?
A relationship between two objects
Client Supplier
❖ Purpose
Determine where structural relationships are NOT required
29
Dependencies vs. Associations
Field reference
Association
Supplier1
30
Associations vs. Dependencies in Collaborations
parameter visibility
Relationships are context-dependent
A context-independent relationship
A summary relationship
31
Local Variable Visibility
ClassA
+ op1 ( )
ClassB
32
Parameter Visibility
ClassA
ClassB
33
Global Visibility
ClassA
+ op1 ( )
ClassB
+ utilityOp ( )
34
Identifying Dependencies: Considerations
35
Example: Define Dependencies (before)
<<interface>>
RegistrationController ICourseCatalogSystem
0..* 1
<<interface>>
RegistrationController ICourseCatalogSystem