bai12

Upload: hieu-andree

Post on 03-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Bai12

    1/6

    8/24/2011

    1

    B mn Cng ngh Phn mmVin CNTT & TTTrng i hc Bch Khoa H Ni

    Bi 12. Biu lp

    Mc ch

    M t khung nhn tnh ca h thng v ccha n vo trong mt m hnh.Minh ha cch c v hiu mt biu lp.M hnh ha mi lin kt (association) v kttp (aggregation) v ch ra cch m hnhchng vo biu lp.M hnh tng qut ha (generalization) trnmt 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_Nameattribute1attribute2attribute3method1()method2()method3()

    5

    Biu din thuc tnhattributeName : Type = Default

    6

  • 8/12/2019 Bai12

    2/6

    8/24/2011

    2

    M t phng thcoperationName([direction] parameter:class ,... ):returnType

    7

    public protected

    private

    Phm vi truy cp (Visibility)

    8

    Phm vi truy cp c bi u di n 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/12/2019 Bai12

    3/6

    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 s elections()

    Professor -name- employeeID : UniqueId-hireDate-status-discipline- maxLoad

    + s ubmitFinalGrade()+ 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

    RegisterForC ours esFor m RegistrationC ontroller

    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

    CourseStudent Schedule

  • 8/12/2019 Bai12

    4/6

    8/24/2011

    4

    Bi s quan h (Multiplicity)

    19

    Professor CourseOffering0..1 0..*0..1 0..*

    instructor

    Biu din bi s quan h

    20

    2..4

    0..1

    1..*

    0..*

    1

    *

    2, 4..6

    UnspecifiedExactly One

    Zero or MoreZero or More

    Zero or One (optional value)One or More

    Specified Range

    Multiple, Disjoint Ranges

    V d v bi s quan h

    21

    RegisterForCoursesForm

    CourseOfferingSchedule0..4

    0..*Student0..*

    1

    RegistrationController 11

    11

    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 hnhha mi quan h ton th-b phn (whole-part)

    23

    PartWhole

    0..1

    1

    V d v kt tp

    24

    RegisterForCoursesForm

    CourseOfferingSchedule0..4

    0..*Student0..*

    1

    RegistrationController 11

    11

    0..1

    0..1

    0..1

  • 8/12/2019 Bai12

    5/6

    8/24/2011

    5

    Cu thnh (Composition) l g?

    Whole

    Composition

    Part

    PartWhole

    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/12/2019 Bai12

    6/6

    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

    CheckingSavings

    Superclass(parent)

    Subclasses(children)

    GeneralizationRelationship

    Descendents

    Ancestor Account

    - balance- name- number

    + withdraw()+ createStatement()

    V d v a k tha

    33

    FlyingThing Animal

    HorseWolf BirdHelicopter Airplane

    Multiple Inheritance

    Manufacturer AManufacturer B Manufacturer C

    OO Principle:Encapsulation

    a hnh (Polymorphism) l g?

    34Remote Control

    Tng qut ha: Thc thi a hnh

    35

    Without Polymorphism

    if animal = Lion thenLion communicate

    else if animal = Tiger thenTiger communicate

    end

    With Polymorphism

    Animal communicate

    Lion Tiger

    Animal

    + communicate ()

    + communicate ()+ communicate ()