relationships between classes

Upload: manoj-mahajan

Post on 06-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Relationships Between Classes

    1/30

    1

    Lecture 8 -Relationships

    between Classesdelivered by John Stockwell

  • 8/3/2019 Relationships Between Classes

    2/30

    2

    Objectives

    At the end of this lecture you will be able to: Interpret the association relationship on a class

    diagram Correctly apply multiplicity and understand its

    significance Correctly configure generalization/specialization

    relationships Distinguish between association and

    compositional aggregation Show all key class relationships on a class

    diagram.

  • 8/3/2019 Relationships Between Classes

    3/30

    3

    Links and Association

  • 8/3/2019 Relationships Between Classes

    4/30

  • 8/3/2019 Relationships Between Classes

    5/30

    5

    Association

  • 8/3/2019 Relationships Between Classes

    6/30

    6

    Multiplicity

    Notation Meaning

    * or 0..* From 0 up to any number

    5..8 From 5 to 8 inclusive

    4..* From 4 up to any number

    1 Exactly 1.

    When there is no number shown 1 is assumed.

  • 8/3/2019 Relationships Between Classes

    7/30

    7

    Association format for interpretation

    on class diagrams

    A link description multiplicity

    at Second Class end (s)

    A link description reversed

    multiplicity at Class end (s)

    A Lecturer teaches on zero or more ModuleOfferings

    A Module Offering is taught by one Lecturer

  • 8/3/2019 Relationships Between Classes

    8/30

    8

    Multiplicity

    The multiplicity then helps us to formulate

    some of the business rules for the

    information system under consideration.

  • 8/3/2019 Relationships Between Classes

    9/30

    9

    Possible links according tomultiplicity specification on class

    diagram

  • 8/3/2019 Relationships Between Classes

    10/30

    10

    Examples of Association

    A Cup of Tea is drunk by one Person. A Person drinks zero or more Cups of Tea.

    A Tea Bag makes one or two Cups of Tea. A Cup of Tea is made by one Tea Bag.

    A Person buys forty or more Tea Bags. A Tea Bag is bought by zero or one Persons.

  • 8/3/2019 Relationships Between Classes

    11/30

    11

    Forming associations

  • 8/3/2019 Relationships Between Classes

    12/30

    12

    Choosing Associations

    Take classes in pairs and form simple

    phrases between them

    Verbs may be chosen from case study

    Consider SFU

  • 8/3/2019 Relationships Between Classes

    13/30

    13

    Choosing Associations

    Student Module Lecturer

    Semester Module Offering Invoice

  • 8/3/2019 Relationships Between Classes

    14/30

    14

    Choosing Associations

    Student studies Modules ?

    Student registers on Module Offering ?

    Student learns from Lecturer ?

    Student ----------- Semester ????

  • 8/3/2019 Relationships Between Classes

    15/30

    15

    Choosing Associations

    Student is sent Invoice

    Module results in Module Offering

    Lecturer teaches Module Offering

    Module Offering occurs in Semester

  • 8/3/2019 Relationships Between Classes

    16/30

    16

    Association relationships onSFU

  • 8/3/2019 Relationships Between Classes

    17/30

    17

    Inheritance

    (Generalization/Specialization)

    Two or more classes appear to share commoncharacteristics

    Object-oriented programming languagesenable us to use the same code to generatethe common features of these classes

    If a class is in existence it may be possible tore-use the class and inherit characteristicsfrom it that can then be refined to give us amore specialized version of it

  • 8/3/2019 Relationships Between Classes

    18/30

    18

    Inheritance The class from which the characteristics are

    inherited is called the super-class

    The class or classes that inherit from it are

    known as the sub-classes The characteristics that are inherited are the

    attributes and the operations of the super-

    class

  • 8/3/2019 Relationships Between Classes

    19/30

    19

    Inheritance In addition the relationships that the super-

    class has to other classes is also inherited bythe subclasses.

    If class A is the super-class and class B is asub-class then we should be able to sayclass B is-a-kind-of class A . It should alsobe clear that there are a number ofcharacteristics in the super-class that thesub-class can sensibly inherit.

  • 8/3/2019 Relationships Between Classes

    20/30

    20

    Inheritance

    (Generalization/Specialization)

  • 8/3/2019 Relationships Between Classes

    21/30

    21

    Inheritance

    Inheritance may be deduced from two

    perspectives.

    A super-class or generalization might

    suggest sub-classes or specializations. Similar sub-classes or specializations

    suggest a super-class or generalization.

  • 8/3/2019 Relationships Between Classes

    22/30

  • 8/3/2019 Relationships Between Classes

    23/30

    23

    Generalization/Specialization onSFU

  • 8/3/2019 Relationships Between Classes

    24/30

    24

    Aggregation and composition

    Aggregation is less important than the

    association and inheritance

    It exists in two forms ordinary aggregation

    a stronger form known as compositional

    aggregation or sometimes simply a composition

  • 8/3/2019 Relationships Between Classes

    25/30

    25

    Composition

    Composition is-a-part-of. The test to see if

    composition exists is twofold

    Does it make sense to say that one class is a

    part of another class? Is there a life dependendency ?

    If the answer to both questions is yes then the

    smaller of the two classes considered has itslife dependent on the larger class.

  • 8/3/2019 Relationships Between Classes

    26/30

    26

    Composition

  • 8/3/2019 Relationships Between Classes

    27/30

    27

    Class diagram for SFU so far

  • 8/3/2019 Relationships Between Classes

    28/30

    28

  • 8/3/2019 Relationships Between Classes

    29/30

    29

    Can you understand theserelationships ?

  • 8/3/2019 Relationships Between Classes

    30/30

    30

    References

    Bennett, S., McRobb, S. and Farmer,R.

    Object-Oriented Systems Analysis and

    Design using UML, London: McGraw-Hill,

    2002 Britton, C. and Daoke, J. Object-Oriented

    Systems Development a gentle

    introduction, London: McGraw-Hill, 2000