Bai 12

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

8/24/2011

1
B mn Cng ngh Phn mm
Vin CNTT & TT
Trng i hc Bch Khoa H Ni
LP TRNH HUNG I TUONG
Bi 12. Biu lp
Mc ch
M t khung nhn tnh ca h thng v cch
a n vo trong mt m hnh.
Minh ha cch c v hiu mt biu lp.
M hnh ha mi lin kt (association) v kt
tp (aggregation) v ch ra cch m hnh
chng vo biu lp.
M hnh tng qut ha (generalization) trn
mt biu lp.
2
Ni dung
1. Biu lp (Class diagram)
2. Lin kt (Association)
3. Kt tp (Aggregation)
4. Tng qut ha (Generalization)
3
Ni dung
1. Biu lp (Class diagram)
2. Lin kt (Association)
3. Kt tp (Aggregation)
4. Tng qut ha (Generalization)
4
1.1. Lp (Class)
Class_Name
attribute1
attribute2
attribute3
method1()
method2()
method3()
5
Biu din thuc tnh
attributeName : Type = Default
6
8/24/2011
2
M t phng thc
operationName([direction] parameter:class,...):returnType
7
public protected
private
Phm vi truy cp (Visibility)
8
Phm vi truy cp c biu din nh th
no?
9
Class1
- privateAttribute
+ publicAttribute
# protectedAttribute
- privateOperation ()
+ publicOPeration ()
# protecteOperation ()
Phm vi (Scope)
Class1
- classifierScopeAttr
- instanceScopeAttr
+ classifierScopeOp ()
+ instanceScopeOp ()
10
V d: Scope
Student
- name
- address
- nextAvailID : int
+ addSchedule ([in] theSchedule : Schedule, [in] forSemester : Semester)
+ getSchedule ([in] forSemester : Semester) : Schedule
+ hasPrerequisites ([in] forCourseOffering : CourseOffering) : boolean
# passed ([in] theCourseOffering : CourseOffering) : boolean
+ getNextAvailID () : int
- studentID
11
1.2. Biu lp l g?
Biu lp ch ra s tn ti ca cc lp
12
8/24/2011
3
Biu lp (Class Diagram CD)
Khung nhn tnh ca h thng
13
CloseRegistrationForm
+ open()
+ close registration()
Student
+ get tuition()
+ add schedule()
+ get schedule()
+ delete schedule()
+ has pre-requisites()
Schedule
- semester
+ commit()
+ select alternate()
+ remove offering()
+ level()
+ cancel()
+ get cost()
+ delete()
+ submit()
+ save()
+ any conflicts?()
+ create with offerings()
+ update with new selections()
Professor
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad
+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
+ teachClass()
CloseRegistrationController
+ is registration open?()
+ close registration()
V d Biu lp
C cch no tt hn t chc biu lp?
14
CloseRegistrationForm
LoginForm
Professor
BillingSystem
CloseRegistrationController
RegisterForCoursesForm
Course
CourseCatalogSystem
Student
RegistrationController
CourseOffering
Schedule
Gi (package)
University
Artifacts
15
V d: Registration Package
16
Registration
CloseRegistrationForm CloseRegistrationController
RegisterForCoursesForm RegistrationController
Ni dung
1. Biu lp (Class diagram)
2. Lin kt (Association)
3. Kt tp (Aggregation)
4. Tng qut ha (Generalization)
17
Lin kt (association) l g?
Mi lin h ng ngha gia hai hay nhiu lp
18
Course Student Schedule
8/24/2011
4
Bi s quan h (Multiplicity)
19
Professor CourseOffering
0..1 0..* 0..1 0..*
instructor
Biu din bi s quan h
20
2..4
0..1
1..*
0..*
1
*
2, 4..6
Unspecified
Exactly One
Zero or More
Zero or More
Zero or One (optional value)
One or More
Specified Range
Multiple, Disjoint Ranges
V d v bi s quan h
21
RegisterForCoursesForm
CourseOffering Schedule
0..4
0..*
Student
0..*
1
RegistrationController
1
1
1
1
0..1
0..1
0..1
Ni dung
1. Biu lp (Class diagram)
2. Lin kt (Association)
3. Kt tp (Aggregation)
4. Tng qut ha (Generalization)
22
Kt tp (aggregation) l g?
L mt dng c bit ca lin kt m hnh
ha mi quan h ton th-b phn (whole-
part)
23
Part Whole
0..1
1
V d v kt tp
24
RegisterForCoursesForm
CourseOffering Schedule
0..4
0..*
Student
0..*
1
RegistrationController
1
1
1
1
0..1
0..1
0..1
8/24/2011
5
Cu thnh (Composition) l g?
Whole
Composition
Part
Part Whole
25
Association, Aggregation and Composition
Mi quan h gia cc lp
(relationship)
26
V d Association
public class StudentRegistrar {
public StudentRegistrar (){
(new RecordManager()).initialize();
}
}
27
V d Aggregration vs. Composition
28
Ni dung
1. Biu lp (Class diagram)
2. Lin kt (Association)
3. Kt tp (Aggregation)
4. Tng qut ha
(Generalization)
29
Tng qut ha (Generalization)
L mi lin h l mt loi (is a kind of)
30
8/24/2011
6
There are no direct instances of Animal
Lion Tiger
Animal
+ communicate ()
+ communicate () + communicate ()
Lp tru tng v lp c th
(Abstract and Concrete Class)
31
All objects are either lions or tigers
Abstract class
Abstract operation
Communication
Discriminator
V d v n k tha
32
Checking Savings
Superclass
(parent)
Subclasses
(children)
Generalization
Relationship
Descendents
Ancestor
Account
- balance
- name
- number
+ withdraw()
+ createStatement()
V d v a k tha
33
FlyingThing Animal
Horse Wolf Bird Helicopter Airplane
Multiple Inheritance
Manufacturer A
Manufacturer B
Manufacturer C
OO Principle:
Encapsulation
a hnh (Polymorphism) l g?
34
Remote Control
Tng qut ha: Thc thi a hnh
35
Without Polymorphism
if animal = Lion then
Lion communicate
else if animal = Tiger then
Tiger communicate
end
With Polymorphism
Animal communicate
Lion Tiger
Animal
+ communicate ()
+ communicate () + communicate ()

You might also like