Waterloo - Uml 2

28
WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE Introduction to Introduction to Unified Modelling Language (UML) Unified Modelling Language (UML) (part 2- Class diagram, Associations) (part 2- Class diagram, Associations) CS 446/646 ECE452 May 6 th , 2011 Material covered in this lecture is based on various chapters from UML 2 and the Unified Process- 2 nd  Edition Practical Object Oriented Analysis & Design IMPORTANT NOTICE TO STUDENTS These slides are NOT to be used as a replacement for student notes. These slides are sometimes vague and incomplete on purpose to spark a class discussion

description

uml2

Transcript of Waterloo - Uml 2

  • WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    IntroductiontoIntroductiontoUnifiedModellingLanguage(UML)UnifiedModellingLanguage(UML)

    (part2Classdiagram,Associations)(part2Classdiagram,Associations)

    CS446/646ECE452May6th,2011

    MaterialcoveredinthislectureisbasedonvariouschaptersfromUML2andtheUnifiedProcess2ndEditionPracticalObjectOrientedAnalysis&Design

    IMPORTANT NOTICE TO STUDENTSThese slides are NOT to be used as a replacement for student notes.

    These slides are sometimes vague and incomplete on purpose to spark a class discussion

  • 2011-05-04CS446/646 ECE452 2WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    ObjectsWhat are Objects a discrete entity with a well-defined boundary that

    encapsulates state and behaviour; an instance of a class UML Reference Manual, 2nd Edition-2004

    Observations an instance of a class state is maintained in fields behaviour is implemented via methods every object is uniquely identified

  • 2011-05-04CS446/646 ECE452 3WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    UMLObjectNotation

    object:class

    accountNumber : String = 123owner : String = Jim Andrewbalance : double = 300.00

    Representation box with two

    compartments object identifier

    always underlined anonymous objects : instanceOf

    attribute compartment may omit some or all fields

    :class

    accountNumber : String = 123owner : String = Jim Andrewbalance : double = 300.00

  • 2011-05-04CS446/646 ECE452 4WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    ClassesWhat are Classes the descriptor for a set of objects that share the same

    attributes, operations, methods, relationships, and behaviour UML Reference Manual, 2nd Edition-2004

    template for objects with similar features

  • 2011-05-04CS446/646 ECE452 5WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    UMLClassNotation

    entityBankAccount

    {author = Jim,status = tested }

    -accountNumber : String -owner : String -balance : double

    +create (number : String, owner : String) +deposit (amount : double) +getAccountNumber():String +getOwner():String

    name compartment

    attribute compartment

    operation compartment

    class name stereotype tagged value

    visibilityclass scope operation

  • 2011-05-04CS446/646 ECE452 6WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    UMLClassNotation

    exerciseStudentToDo

    + reviewAndLearnMissingUMLClassNotations()

  • 2011-05-04CS446/646 ECE452 7WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    HowMuchtoShow?Scenarios scenario 1: inter-class relationship

    scenario 2: behaviour of a class or classes

    scenario 3: entity classes representing data entities

  • 2011-05-04CS446/646 ECE452 8WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    HowMuchtoShow?Scenarios scenario 1: inter-class relationship

    class boxes are probably enough with namecompartment only

    scenario 2: behaviour of a class or classes class boxes with name & operations compartment

    scenario 3: entity classes representing data entities ask the class?

  • 2011-05-04CS446/646 ECE452 9WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    AnalysisClassesWhat is an Analysis Class? represents an important concept of the problem domain maps on to real-world concepts an attempt to capture the big picture

    BankAccount accountNumber owner balance

    deposit () getAccountNumber() getOwner()

    SavingAccount

    Q: what about savings account sub-class of BankAccount?

  • 2011-05-04CS446/646 ECE452 10WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    AnalysisClassesImportant Analysis Classes boundary

    a class that mediates interaction between thesystem (or subsystem) and its environment

    control a class that encapsulates use case specific behaviour

    entity a class that is used to model persistence information

  • 2011-05-04CS446/646 ECE452 11WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    AnalysisClassesObservations name reflects the intent of abstraction focus clearly defined/understood small & well defined set of responsibilities high cohesion & low coupling

    BankAccount accountNumber owner balance

    deposit () withdraw() calculateInterest()

    clientPromotion()

    Q: responsibility, cohesion & coupling?Q: can we use analysis classes for implementation?

  • 2011-05-04CS446/646 ECE452 12WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    DesignClassesWhat is a Design Class? Integrates the problem domain & solution domain

    problem domain refined analysis classes solution domain implementation specific classes

    are complete, ready to be implementedBankAccount

    -accountNumber : String -owner : String -balance : double = 0 +BankAccount (owner:String, number:String) +deposit (m:double):void +withdraw (m:double):void - validateWithdraw():boolean +getOwner():String

    1

    2

    3

  • 2011-05-04CS446/646 ECE452 13WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    DesignClassesConcerns responsibility

    the public methods imply a contract code evolution should be considered

    inheritance major concern of design classes (why?)

  • 2011-05-04CS446/646 ECE452 14WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    InheritanceUnderReviewConcerns the strongest form of coupling between classes fragile base class problem

    changes in the base class impact subclasses inflexible to change

    fixed at runtime

  • 2011-05-04CS446/646 ECE452 15WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    Example:AmbitiousJohnHow to promote john to be a manager? john:Programmer vs. john:Manager

  • 2011-05-04CS446/646 ECE452 16WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    Example:AmbitiousJohnAggregation to rescue employee has a job

  • 2011-05-04CS446/646 ECE452 17WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    InheritanceorInterfaceInheritance interface & implementation concerns with reuse

    Interface interface only concerns with functionality contract

    design by contract concerns with reuse (what?)

  • 2011-05-04CS446/646 ECE452 18WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    FurtherConsiderationsStudent Self-Study Templates Nested classes Multiple Inheritance

  • 2011-05-04CS446/646 ECE452 19WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    AssociationRelationshipWhat is an Association? connection between two things (usually classes) for a link between two object, there must be an

    association between the class of those objects link is an instance of an association link can be represented by dependency relationship

    Group User

    admin:Group john:User

    instanceOfinstanceOf instanceOf

    association

    link

  • 2011-05-04CS446/646 ECE452 20WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    ExampleDecipher this a Company can have

    exactly seven employees a Person can be employed

    by exactly one Company a BankAccount can have exactly one owner a Person may have zero to many BankAccounts a BankAccount can have one or many operators a Person may operate zero to many BankAccounts

  • 2011-05-04CS446/646 ECE452 21WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    ReflexiveAssociationDefinition A class has an association with itself

  • 2011-05-04CS446/646 ECE452 22WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    ReflexiveAssociationClass Diagram

    Object Diagram

  • 2011-05-04CS446/646 ECE452 23WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    NavigationReview the following navigation notation & rules uni-direction & bi-direction associations

  • 2011-05-04CS446/646 ECE452 24WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    TypesofAssociationComposition strong whole/part (owner/slave) relationship between

    classes

    can we have more than 1 parent? what happens when the parent is destroyed?

  • 2011-05-04CS446/646 ECE452 25WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    TypesofAssociationAggregation weaker whole/part relationship between classes

    classes can exist on their own observations

    a computer may be attached tozero or more printers

    many computers can use a printer printer may exist even if there are no computers aggregation is transitive

  • 2011-05-04CS446/646 ECE452 26WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    AssociationClassesAnalysis classes

    Design classes

  • 2011-05-04CS446/646 ECE452 27WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    AssociationClassesObservations association classes are purely analysis classes convert association class into normal design class

    use the various relationships to clarify association (aggregation, composition, dependency)

    additional constraints to refine the model navigation, multiplicity

  • 2011-05-04CS446/646 ECE452 28WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

    StudentStudyCompulsory Reading Sequence diagram State diagram Activity diagram

    Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28