SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Class Diagrams using UML




Object-Oriented Software Systems Engineering – Chapter 4   Slide 1
Objectives

 In this chapter we will:
  Introduce class diagram notation
  Discuss how to identify problem domain classes
  Discuss the different relationships which exist
   between classes
  Introduce the concept of an Interface




Object-Oriented Software Systems Engineering – Chapter 4   Slide 2
Class Diagram
                 - order processing (Association with navigability
                                   adornments)
    Order                                                                     Customer
          {persistent}                                                               {persistent}
 dateReceived                *                belong to              1
 isPrepaid                                                                name : Name
 number : String                                                          address : String
 price : Money                                                            creditRating() : String
 dispatch()
 close()
            1
                {if Order.customer.creditRating is
                “poor” then Order.isPrepaid
                Must be true}                            Corporate Customer                Personal Customer
                                                                     {persistent}                   {persistent}
                                                         contactName
      has




                                                                                          creditCard#
                                                         creditRating
                                                         creditLimit
                                                         remind()
            *                                            billForMonth(bn : Integer)
     OrderLine
          {persistent}
 quantity : Integer
                                   refer to          1
 price : Money               *
 isSatisfied : Boolean                                     Product


Object-Oriented Software Systems Engineering – Chapter 4                                                Slide 3
Class Diagrams

       Purpose
          model the static view of a system
          how they are related, but not how they interact to
           achieve particular behaviour
          model static relationships between classes
              association and generalisation are the two
               principal kinds of relationships
       Scope
            abstraction : the key domain class
            only the aspects of the domain which are important
             to the application
            a class should be named using the vocabulary of the
             domain



Object-Oriented Software Systems Engineering – Chapter 4        Slide 4
Static Modelling - Class

  Class
     name
     attributes - describe characteristics of the objects
     operations - used to manipulate attributes and to perform
      other actions
  Attribute
     has type - which tells what values the attribute can take
     visibility - tells whether the attribute is visible and can be
      referenced from classes other than the one in which it is
      defined (private, public, protected)
     may have a default value - assigned at the time an object
      of the class is created




Object-Oriented Software Systems Engineering – Chapter 4       Slide 5
Static Modelling - Class

  Operations (methods)
     a function defined within a class and can be only applied
      to the objects of that class
     describe what any object of the class can do
     describe the interface to the class - what the class can do
      and what services it offers
     signature, visibility, scope




Object-Oriented Software Systems Engineering – Chapter 4    Slide 6
O-O Concepts Messages and Methods

  Objects perform work when sent messages
  Messages are sent to objects to invoke their behaviour
    (methods)
       For example a Customer object could sent a message to a
        pump to start pumping

  Methods are the implementation of the behaviour
       invoked when a message arrives
       they only have access to an objects attributes (data)- unless
        data attributes are declared as static




Object-Oriented Software Systems Engineering – Chapter 4           Slide 7
O-O Concepts Messages and Methods

  Methods are defined by their signature
       visibility(public,private,protected,default)
       return type
       method name
       method parameters


  Different methods can have same name but a different
    parameters,these will decide which method is invoked at
    runtime (method overloading)




Object-Oriented Software Systems Engineering – Chapter 4   Slide 8
O-O Concepts Full Class UML Notation


                                    Frame                                name
Underlining
denotes static
                        Header : FrameHeader
                      - FrameID : Long                                   attributes



private               - encrypt()
protected            # setCheckSum()
                                                                         operations
public               + addMessage(m : Message) : Status



                                                             signature

  Object-Oriented Software Systems Engineering – Chapter 4                 Slide 9
Static Modelling Association - Relationships
     Association
      relationship that describes a set of links
      class A and class B are associated if
           an object of class A sends a message to an object of
            class B
           an object of class A creates an object of class B
           an object of class A has an attribute whose values are
            objects of class B or collections of objects of class B
           an object of class A receives a message with an object
            of class B as an argument
     Multiplicity
      a range that tells how many objects are linked
      placed near the class it is applicable to
      ranges : n..m          0..1      0..*    1..*       2   1,2,4,8
Object-Oriented Software Systems Engineering – Chapter 4                 Slide 10
An Example of Association


        Car                                                           Person
                                        owns
    model          company car                             driver    name

                   0..*                                       1..*
    opname()                                                         opname()


                      Multiplicity       Role        Name


                Name                                            Role
                                                  indicates the role played by
  verb/noun from a problem domain
                                                  the class in terms of
                                                  association placed near the
                                                  class it applies to

Object-Oriented Software Systems Engineering – Chapter 4                        Slide 11
Static Modelling – Normal Association

  If an association is only ever used in one direction
    it can be labeled with an arrow head at the end


                                                           <<control>>
                      <<boundary>>
                                                           PumpControl
                         Nozzle

                       In
                                     triggers
                       out
                       start
                       stop




Object-Oriented Software Systems Engineering – Chapter 4                 Slide 12
Static Modelling Generalization Relationship

  Generalization
    relationship between a general thing
        (superclass or parent) and a more specific kind
        of that thing (subclass of child)
      the child will inherit all the structure and
        behaviour of the parent
      the child may add new structure and behaviour
        or it may modify the behaviour of the parent
      the child is substitutable for the parent




Object-Oriented Software Systems Engineering – Chapter 4   Slide 13
Examples of Generalisation

  A taxonomic relation between a more general and
    a more specific element
  The more specific element
       is fully consistent with the more general
       contains additional properties

  The relationship between the classes is
    inheritance
       the specific class inherits everything (attributes,
        operations, relations) from the general class




Object-Oriented Software Systems Engineering – Chapter 4      Slide 14
An Example of Generalisation


                                                 Customer
                                         name
                                         address

                                         creditRating():String




                          Corporate                          Personal
                          Customer                           Customer
                         contactName                         creditCard#
                         creditRating
                         creditLimit

                         remind()
                         billForMonth(Integer)




Object-Oriented Software Systems Engineering – Chapter 4                   Slide 15
An Example of Generalisation



                                     Vehicle




                                                     Boat
                      Car




          SportCar           Truck             MotorBoat    SailingBoat




Object-Oriented Software Systems Engineering – Chapter 4                  Slide 16
Static Modelling Aggregation with
                               examples


             Aggregation indicates that a relationship between
             the classes is "whole-part”.
• Shared aggregation
   the parts may be parts of many wholes
                                                        Membership
                                                club                 member
                                    Team                                       Person

                                                 0..*                   1..*

                                                                         Car
• Composition aggregation
  strong ownership - the whole owns the parts,
  the part lives inside the whole                                4
                                                               Wheel            Engine


  Object-Oriented Software Systems Engineering – Chapter 4                     Slide 17
Static Modelling - Aggregation

  Aggregation indicates that a relationship between
   the classes is "whole-part”
  Shared aggregation – the parts may be parts of
   many wholes


                                        Membership
                                club                 member
                   Team                                           Person

                                 0..*                      1..*




Object-Oriented Software Systems Engineering – Chapter 4                   Slide 18
Static Modelling - Aggregation

  Composition aggregation
     Strong ownership
     The whole owns the parts; the parts live inside the whole



                                       Car



                               4
                             Wheel             Engine




Object-Oriented Software Systems Engineering – Chapter 4   Slide 19
Identification of Classes

  Noun identification technique
  This technique involves two stages:


  Select all the nouns and noun phrases in a
   requirements specification of the system as
   candidates for classes
  Discard candidate which are inappropriate for any
   reasons

  How do we decide which are inappropriate?



Object-Oriented Software Systems Engineering – Chapter 4   Slide 20
Discarding Candidate Classes

  Candidates may be inappropriate for many reasons:
       redundant : the same class is given more than one name

       vague : cannot tell unambiguously what is meant by a noun

       an event or an operation : where noun refers to something
        which is done to or by the system
       an attribute : where the noun refers to something simple
        with no interesting behaviour
       meta-language : where the noun forms part of the way we
        define things (e.g., requirements, system)
       outside the scope of the system : where the noun is relevant
        to describing how the system works but does not refer to
        something inside the system


Object-Oriented Software Systems Engineering – Chapter 4    Slide 21
Identifying Classes for a Library

  Consider the following example


  A library contains books and journals. It may have
    several copies of a given book. Some of the books
    are for short term loans only. All other books may
    be borrowed by any library member for three
    weeks. Members of the library can normally
    borrow up to six items at a time, but members of
    staff may borrow up to 12 items at one time. Only
    members of staff may borrow journals.




Object-Oriented Software Systems Engineering – Chapter 4   Slide 22
LibraryMember                      Copy of Book                       Book
        {persistent}                      {persistent}                        {persistent}
                                   CopyID: int
                       0..1   0..* MemberID : Object     1..*    1 Title: String
                                                                       Publisher: String
                                   LoanTime: int                       Author: String
                                                                       ISBN: int
                                   borrowed()
                                                                       TotalCopies: int
                                   returned()
                                                                       AvailabelCopies: int
                                   updateAvaCopies()
                                   reservedCopy()                      addBook ()
                                                                       removeBook()
                                                                       findBook()
                                                                       borrowable()



                                                                         Journal
                                                                              {persistent}
   MemberOfStaff
        {persistent}
                       0..1                                     0..*


                                                                       addJournal ()
                                                                       removeJournal(
                                                                       )
                                                                       findJournal()
Object-Oriented Software Systems Engineering – Chapter 4                        Slide 23
Examples of Class Diagrams

  On the next two slides examples of class diagrams
    are given
       One relating to course management
       The other relating to order processing
  Study the diagrams to see if you can understand
    them




Object-Oriented Software Systems Engineering – Chapter 4   Slide 24
School                                        Department
                {persistent}                              {persistent}
                                                                                                      Chairperson
 name : Name                                     name : Name              0..1
                                    has
 address : String                                address : String
 PhoneNo : Number                                PhoneNo : Number
                               1          1..*                            1..*
 addStudent()                                    addStaff
 removeStudent()                                 removeStaff
 getStudent()                                    getStaff
 getAllStudent()                                 getAllStaff
 addDepartment()
 removeDepartment()                                     1..*




                                                                                                  assigned to
 getDepartment()
 getAllDepartment()




                                                         own
      1..*
                                                        1..*
       member




                                                        Course                                    1..*                     0..1
                                                           {persistent}                           Academic Staff
           *                                         name : Name
      Student                                                                                         {persistent}
                                                     courseID : Number
         {persistent}              attends                                       teaches          name : Name
                                                     addCourse
 name : Name                                                                               1..*
                                                     updatCourse           *
 studentID : Number            *                 *   getCourse

Object-Oriented Software Systems Engineering – Chapter 4                                                        Slide 25
School                                        Department
                {persistent}                              {persistent}
                                                                                                      Chairperson
 name : Name                                     name : Name              0..1
                                    has
 address : String                                address : String
 PhoneNo : Number                                PhoneNo : Number
                               1          1..*                            1..*
 addStudent()                                    addStaff
 removeStudent()                                 removeStaff
 getStudent()                                    getStaff
 getAllStudent()                                 getAllStaff
 addDepartment()
 removeDepartment()                                     1..*




                                                                                                  assigned to
 getDepartment()
 getAllDepartment()




                                                         own
      1..*
                                                        1..*
       member




                                                        Course                                    1..*                     0..1
                                                           {persistent}                           Academic Staff
           *                                         name : Name
      Student                                                                                         {persistent}
                                                     courseID : Number
         {persistent}              attends                                       teaches          name : Name
                                                     addCourse
 name : Name                                                                               1..*
                                                     updatCourse           *
 studentID : Number            *                 *   getCourse


Object-Oriented Software Systems Engineering – Chapter 4                                                        Slide 26
Order                                                             Customer
            {persistent}                                                       {persistent}
   dateReceived            *              belong to             1
   isPrepaid                                                        name : Name
   number : String                                                  address : String
   price : Money                                                    creditRating() : String
   dispatch()
   close()
              1

                                                  Corporate Customer                 Personal Customer
                                                              {persistent}                    {persistent}
                                                  contactName
        has




                                                                                    creditCard#
                                                  creditRating
                                                  creditLimit
                                                  remind()
              *                                   billForMonth(bn : Integer)
       OrderLine
            {persistent}
   quantity : Integer
                               refer to     1
   price : Money           *
   isSatisfied : Boolean                              Product




Object-Oriented Software Systems Engineering – Chapter 4                                      Slide 27
Realisation

  A semantic relationship between classifiers in
   which one classifier specifies a contract that
   another classifier guarantees to carry out
  semantically a cross between a dependency and
   generalisation
  used in two cases
                     Use case                                   collaboration
                                        realizes             Order
                   Place order
                                                           management



                <<interface>>
                UserInterface            realizes
                                                           Bank Account



Object-Oriented Software Systems Engineering – Chapter 4                   Slide 28
Realizing use cases - Relationship

  Realized in a collaboration
     shows an internal implementation dependent solution of
      a use case in terms of classes & their relationships

                          <<realizes>>


                                                             Collaboration
   Use Case
                                                                                       <<implements>>
                                         <<implements>>

                                                            <<implements>>



  Use case description:                       Class A                        Class B                Class C
  1. Insert the coins
  2. Choose a drink
  3. Deliver a drink                        Oper1()                     Oper1()                   Oper1()
  4. E.t.c                                  Oper2()                     Oper2()                   Oper2()
                                            Oper3() e.t.c               Oper3() e.t.c             Oper3() e.t.c




Object-Oriented Software Systems Engineering – Chapter 4                                                Slide 29
Interfaces in UML

 • UML has a short hand notation for representing
    interfaces but does not show the methods
    associated with the interface
                                         BankAccount

    AccountHolder 1                name:String                                BankEmployee
                           1..*                               1..*        1
                                   balance:Currency
                  has              accountNo:String              looksAfter

                                   credit(Amount:double)
                                   debit(Amount:double)
                                   suspend()
                                   chargeFee(Amount:double)
                                   getBalance();double
                   UserInterface
     interface                                                       administers



Object-Oriented Software Systems Engineering – Chapter 4                           Slide 30
Interfaces in UML

 • A more detailed representation


           <<interface>>                    realises                BankAccount
           UserInterface
                                                              name:String
         credit(Amount:long)                                  balance:long
         debit(Amount:long)                                   accountNo:Int
         getBalance():long
                                                              credit(Amount:long)
                                                              debit(Amount:long)
        <<uses>>               dependency
                                                              suspend()
                                  1                    1..*   chargeFee(Amount:long)
            AccountHolder                                     getBalance();long
                                  has




Object-Oriented Software Systems Engineering – Chapter 4                               Slide 31
Dependencies - relationship

  Dependency is a using relationship
     a change in one thing may effect another
     shown as a stereotype e.g. friend
            one class takes an object of another class as a parameter
            one class accesses a global object of another class
            one class calls a class scope method in another class


                                                  <<friend>>
  Example                   Class A                   Class B
     friend
     specifies that source is given special visibility into the target
     instanceOf
     source object is an instance of the target classifier
     instantiate
     source creates instances of the target

Object-Oriented Software Systems Engineering – Chapter 4            Slide 32
Summary

 In this chapter we have:
  Introduced class diagram notation
  Discussed how to identify problem domain
   classes
  Discussed the different relationships which exist
   between classes
  Introduced the concept of an Interface




Object-Oriented Software Systems Engineering – Chapter 4   Slide 33

Weitere ähnliche Inhalte

Was ist angesagt? (19)

Object modeling
Object modelingObject modeling
Object modeling
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
01 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_0101 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_01
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Ooad
OoadOoad
Ooad
 
Ooad 2marks
Ooad 2marksOoad 2marks
Ooad 2marks
 
O ops concepts
O ops conceptsO ops concepts
O ops concepts
 
CSMR10b.ppt
CSMR10b.pptCSMR10b.ppt
CSMR10b.ppt
 
2008 Sccc Smalltalk
2008 Sccc Smalltalk2008 Sccc Smalltalk
2008 Sccc Smalltalk
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Classes And Methods
Classes And MethodsClasses And Methods
Classes And Methods
 
09 ooad uml-11
09 ooad uml-1109 ooad uml-11
09 ooad uml-11
 
Unit 2
Unit 2Unit 2
Unit 2
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
01 gui 01
01 gui 0101 gui 01
01 gui 01
 
Claas diagram
Claas diagramClaas diagram
Claas diagram
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 

Andere mochten auch

School Management System ppt
School Management System pptSchool Management System ppt
School Management System pptMohsin Ali
 
Library Management System
Library Management SystemLibrary Management System
Library Management SystemAnit Thapaliya
 
VTU Final Year Engineering Project Title List for Computer Science Engineerin...
VTU Final Year Engineering Project Title List for Computer Science Engineerin...VTU Final Year Engineering Project Title List for Computer Science Engineerin...
VTU Final Year Engineering Project Title List for Computer Science Engineerin...zettanetworks
 
Library System Implementation with JavaFx
Library System Implementation with JavaFxLibrary System Implementation with JavaFx
Library System Implementation with JavaFxJivan Nepali
 
Lecture-03 Introduction to UML
Lecture-03 Introduction to UMLLecture-03 Introduction to UML
Lecture-03 Introduction to UMLartgreen
 
Slide 5 Class Diagram
Slide 5 Class DiagramSlide 5 Class Diagram
Slide 5 Class DiagramNiloy Rocker
 
Library management
Library managementLibrary management
Library managementakki_hearts
 
ERP on School Management System
ERP on School Management SystemERP on School Management System
ERP on School Management SystemAmit Gandhi
 
School management system
School management systemSchool management system
School management systemSoumya Behera
 
School management system
School management systemSchool management system
School management systemasd143
 
Online Library Management
Online Library ManagementOnline Library Management
Online Library ManagementVarsha Sarkar
 
Online shopping cart system file
Online shopping cart system fileOnline shopping cart system file
Online shopping cart system fileSunil Jaiswal
 
Library Management System PPT
Library Management System PPTLibrary Management System PPT
Library Management System PPTTamaghna Banerjee
 
Bio atm with-microsoft_finger_print_sdk
Bio atm with-microsoft_finger_print_sdkBio atm with-microsoft_finger_print_sdk
Bio atm with-microsoft_finger_print_sdkMahesh Shitole
 

Andere mochten auch (20)

School Management System ppt
School Management System pptSchool Management System ppt
School Management System ppt
 
Library Management System
Library Management SystemLibrary Management System
Library Management System
 
VTU Final Year Engineering Project Title List for Computer Science Engineerin...
VTU Final Year Engineering Project Title List for Computer Science Engineerin...VTU Final Year Engineering Project Title List for Computer Science Engineerin...
VTU Final Year Engineering Project Title List for Computer Science Engineerin...
 
8.Inheritance
8.Inheritance8.Inheritance
8.Inheritance
 
Library System Implementation with JavaFx
Library System Implementation with JavaFxLibrary System Implementation with JavaFx
Library System Implementation with JavaFx
 
Lecture-03 Introduction to UML
Lecture-03 Introduction to UMLLecture-03 Introduction to UML
Lecture-03 Introduction to UML
 
E-library mangament system
E-library mangament systemE-library mangament system
E-library mangament system
 
Class Diagram
Class DiagramClass Diagram
Class Diagram
 
Slide 5 Class Diagram
Slide 5 Class DiagramSlide 5 Class Diagram
Slide 5 Class Diagram
 
UML ile Modelleme
UML ile ModellemeUML ile Modelleme
UML ile Modelleme
 
Library management
Library managementLibrary management
Library management
 
ERP on School Management System
ERP on School Management SystemERP on School Management System
ERP on School Management System
 
UML Diagrams
UML DiagramsUML Diagrams
UML Diagrams
 
School management system
School management systemSchool management system
School management system
 
School management system
School management systemSchool management system
School management system
 
Online Library Management
Online Library ManagementOnline Library Management
Online Library Management
 
Online shopping cart system file
Online shopping cart system fileOnline shopping cart system file
Online shopping cart system file
 
Library Management System PPT
Library Management System PPTLibrary Management System PPT
Library Management System PPT
 
Bio atm with-microsoft_finger_print_sdk
Bio atm with-microsoft_finger_print_sdkBio atm with-microsoft_finger_print_sdk
Bio atm with-microsoft_finger_print_sdk
 
School Management System
School Management SystemSchool Management System
School Management System
 

Ähnlich wie 4.class diagramsusinguml

UNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptxUNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptxanguraju1
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
A&D - Object Oriented Design using UML
A&D - Object Oriented Design using UMLA&D - Object Oriented Design using UML
A&D - Object Oriented Design using UMLvinay arora
 
B vb script11
B vb script11B vb script11
B vb script11oakhrd
 
06 ooad uml-07
06 ooad uml-0706 ooad uml-07
06 ooad uml-07Niit Care
 
M03 1 Structuraldiagrams
M03 1 StructuraldiagramsM03 1 Structuraldiagrams
M03 1 StructuraldiagramsDang Tuan
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-CNagendra Ram
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programmingNeelesh Shukla
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented DesignAravinth NSP
 
Ch.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptx
Ch.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptxCh.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptx
Ch.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptxSohagSrz
 
ObjectOrientedSystems.ppt
ObjectOrientedSystems.pptObjectOrientedSystems.ppt
ObjectOrientedSystems.pptChishaleFriday
 
3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptxRokaKaram
 

Ähnlich wie 4.class diagramsusinguml (20)

UNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptxUNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptx
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
A&D - Object Oriented Design using UML
A&D - Object Oriented Design using UMLA&D - Object Oriented Design using UML
A&D - Object Oriented Design using UML
 
Slides chapter 11
Slides chapter 11Slides chapter 11
Slides chapter 11
 
B vb script11
B vb script11B vb script11
B vb script11
 
06 ooad uml-07
06 ooad uml-0706 ooad uml-07
06 ooad uml-07
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
M03 1 Structuraldiagrams
M03 1 StructuraldiagramsM03 1 Structuraldiagrams
M03 1 Structuraldiagrams
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-C
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Interfaces & Packages V2
Interfaces & Packages V2Interfaces & Packages V2
Interfaces & Packages V2
 
UML
UMLUML
UML
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
Ch.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptx
Ch.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptxCh.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptx
Ch.03 - Class Diagram_1 OBJECT ORIENTED ANALYSIS AND DESIGN [O] .pptx
 
ObjectOrientedSystems.ppt
ObjectOrientedSystems.pptObjectOrientedSystems.ppt
ObjectOrientedSystems.ppt
 
3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx
 

Mehr von APU

01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_moduleAPU
 
. 1. introduction to object orientation
. 1. introduction to object orientation. 1. introduction to object orientation
. 1. introduction to object orientationAPU
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_moduleAPU
 
9. oo languages
9. oo languages9. oo languages
9. oo languagesAPU
 
8. design patterns
8. design patterns8. design patterns
8. design patternsAPU
 
7. sequence and collaboration diagrams
7. sequence and collaboration diagrams7. sequence and collaboration diagrams
7. sequence and collaboration diagramsAPU
 
6. activity diagrams
6. activity diagrams6. activity diagrams
6. activity diagramsAPU
 
5. state diagrams
5. state diagrams5. state diagrams
5. state diagramsAPU
 
4. class diagrams using uml
4. class diagrams using uml4. class diagrams using uml
4. class diagrams using umlAPU
 
3. use cases
3. use cases3. use cases
3. use casesAPU
 
01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_moduleAPU
 
. 9. oo languages
. 9. oo languages. 9. oo languages
. 9. oo languagesAPU
 
08 aggregation and collection classes
08  aggregation and collection classes08  aggregation and collection classes
08 aggregation and collection classesAPU
 
. 8. design patterns
. 8. design patterns. 8. design patterns
. 8. design patternsAPU
 
. 5. state diagrams
. 5. state diagrams. 5. state diagrams
. 5. state diagramsAPU
 
. 4. class diagrams using uml
. 4. class diagrams using uml. 4. class diagrams using uml
. 4. class diagrams using umlAPU
 
. 2. introduction to uml
. 2. introduction to uml. 2. introduction to uml
. 2. introduction to umlAPU
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_moduleAPU
 
14 file handling
14 file handling14 file handling
14 file handlingAPU
 
13 gui development
13 gui development13 gui development
13 gui developmentAPU
 

Mehr von APU (20)

01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_module
 
. 1. introduction to object orientation
. 1. introduction to object orientation. 1. introduction to object orientation
. 1. introduction to object orientation
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_module
 
9. oo languages
9. oo languages9. oo languages
9. oo languages
 
8. design patterns
8. design patterns8. design patterns
8. design patterns
 
7. sequence and collaboration diagrams
7. sequence and collaboration diagrams7. sequence and collaboration diagrams
7. sequence and collaboration diagrams
 
6. activity diagrams
6. activity diagrams6. activity diagrams
6. activity diagrams
 
5. state diagrams
5. state diagrams5. state diagrams
5. state diagrams
 
4. class diagrams using uml
4. class diagrams using uml4. class diagrams using uml
4. class diagrams using uml
 
3. use cases
3. use cases3. use cases
3. use cases
 
01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_module
 
. 9. oo languages
. 9. oo languages. 9. oo languages
. 9. oo languages
 
08 aggregation and collection classes
08  aggregation and collection classes08  aggregation and collection classes
08 aggregation and collection classes
 
. 8. design patterns
. 8. design patterns. 8. design patterns
. 8. design patterns
 
. 5. state diagrams
. 5. state diagrams. 5. state diagrams
. 5. state diagrams
 
. 4. class diagrams using uml
. 4. class diagrams using uml. 4. class diagrams using uml
. 4. class diagrams using uml
 
. 2. introduction to uml
. 2. introduction to uml. 2. introduction to uml
. 2. introduction to uml
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_module
 
14 file handling
14 file handling14 file handling
14 file handling
 
13 gui development
13 gui development13 gui development
13 gui development
 

4.class diagramsusinguml

  • 1. Class Diagrams using UML Object-Oriented Software Systems Engineering – Chapter 4 Slide 1
  • 2. Objectives In this chapter we will:  Introduce class diagram notation  Discuss how to identify problem domain classes  Discuss the different relationships which exist between classes  Introduce the concept of an Interface Object-Oriented Software Systems Engineering – Chapter 4 Slide 2
  • 3. Class Diagram - order processing (Association with navigability adornments) Order Customer {persistent} {persistent} dateReceived * belong to 1 isPrepaid name : Name number : String address : String price : Money creditRating() : String dispatch() close() 1 {if Order.customer.creditRating is “poor” then Order.isPrepaid Must be true} Corporate Customer Personal Customer {persistent} {persistent} contactName has creditCard# creditRating creditLimit remind() * billForMonth(bn : Integer) OrderLine {persistent} quantity : Integer refer to 1 price : Money * isSatisfied : Boolean Product Object-Oriented Software Systems Engineering – Chapter 4 Slide 3
  • 4. Class Diagrams  Purpose  model the static view of a system  how they are related, but not how they interact to achieve particular behaviour  model static relationships between classes  association and generalisation are the two principal kinds of relationships  Scope  abstraction : the key domain class  only the aspects of the domain which are important to the application  a class should be named using the vocabulary of the domain Object-Oriented Software Systems Engineering – Chapter 4 Slide 4
  • 5. Static Modelling - Class  Class  name  attributes - describe characteristics of the objects  operations - used to manipulate attributes and to perform other actions  Attribute  has type - which tells what values the attribute can take  visibility - tells whether the attribute is visible and can be referenced from classes other than the one in which it is defined (private, public, protected)  may have a default value - assigned at the time an object of the class is created Object-Oriented Software Systems Engineering – Chapter 4 Slide 5
  • 6. Static Modelling - Class  Operations (methods)  a function defined within a class and can be only applied to the objects of that class  describe what any object of the class can do  describe the interface to the class - what the class can do and what services it offers  signature, visibility, scope Object-Oriented Software Systems Engineering – Chapter 4 Slide 6
  • 7. O-O Concepts Messages and Methods  Objects perform work when sent messages  Messages are sent to objects to invoke their behaviour (methods)  For example a Customer object could sent a message to a pump to start pumping  Methods are the implementation of the behaviour  invoked when a message arrives  they only have access to an objects attributes (data)- unless data attributes are declared as static Object-Oriented Software Systems Engineering – Chapter 4 Slide 7
  • 8. O-O Concepts Messages and Methods  Methods are defined by their signature  visibility(public,private,protected,default)  return type  method name  method parameters  Different methods can have same name but a different parameters,these will decide which method is invoked at runtime (method overloading) Object-Oriented Software Systems Engineering – Chapter 4 Slide 8
  • 9. O-O Concepts Full Class UML Notation Frame name Underlining denotes static Header : FrameHeader - FrameID : Long attributes private - encrypt() protected # setCheckSum() operations public + addMessage(m : Message) : Status signature Object-Oriented Software Systems Engineering – Chapter 4 Slide 9
  • 10. Static Modelling Association - Relationships Association  relationship that describes a set of links  class A and class B are associated if  an object of class A sends a message to an object of class B  an object of class A creates an object of class B  an object of class A has an attribute whose values are objects of class B or collections of objects of class B  an object of class A receives a message with an object of class B as an argument Multiplicity  a range that tells how many objects are linked  placed near the class it is applicable to  ranges : n..m 0..1 0..* 1..* 2 1,2,4,8 Object-Oriented Software Systems Engineering – Chapter 4 Slide 10
  • 11. An Example of Association Car Person owns model company car driver name 0..* 1..* opname() opname() Multiplicity Role Name Name Role indicates the role played by verb/noun from a problem domain the class in terms of association placed near the class it applies to Object-Oriented Software Systems Engineering – Chapter 4 Slide 11
  • 12. Static Modelling – Normal Association  If an association is only ever used in one direction it can be labeled with an arrow head at the end <<control>> <<boundary>> PumpControl Nozzle In triggers out start stop Object-Oriented Software Systems Engineering – Chapter 4 Slide 12
  • 13. Static Modelling Generalization Relationship  Generalization relationship between a general thing (superclass or parent) and a more specific kind of that thing (subclass of child) the child will inherit all the structure and behaviour of the parent the child may add new structure and behaviour or it may modify the behaviour of the parent the child is substitutable for the parent Object-Oriented Software Systems Engineering – Chapter 4 Slide 13
  • 14. Examples of Generalisation  A taxonomic relation between a more general and a more specific element  The more specific element  is fully consistent with the more general  contains additional properties  The relationship between the classes is inheritance  the specific class inherits everything (attributes, operations, relations) from the general class Object-Oriented Software Systems Engineering – Chapter 4 Slide 14
  • 15. An Example of Generalisation Customer name address creditRating():String Corporate Personal Customer Customer contactName creditCard# creditRating creditLimit remind() billForMonth(Integer) Object-Oriented Software Systems Engineering – Chapter 4 Slide 15
  • 16. An Example of Generalisation Vehicle Boat Car SportCar Truck MotorBoat SailingBoat Object-Oriented Software Systems Engineering – Chapter 4 Slide 16
  • 17. Static Modelling Aggregation with examples Aggregation indicates that a relationship between the classes is "whole-part”. • Shared aggregation the parts may be parts of many wholes Membership club member Team Person 0..* 1..* Car • Composition aggregation strong ownership - the whole owns the parts, the part lives inside the whole 4 Wheel Engine Object-Oriented Software Systems Engineering – Chapter 4 Slide 17
  • 18. Static Modelling - Aggregation  Aggregation indicates that a relationship between the classes is "whole-part”  Shared aggregation – the parts may be parts of many wholes Membership club member Team Person 0..* 1..* Object-Oriented Software Systems Engineering – Chapter 4 Slide 18
  • 19. Static Modelling - Aggregation  Composition aggregation  Strong ownership  The whole owns the parts; the parts live inside the whole Car 4 Wheel Engine Object-Oriented Software Systems Engineering – Chapter 4 Slide 19
  • 20. Identification of Classes  Noun identification technique  This technique involves two stages:  Select all the nouns and noun phrases in a requirements specification of the system as candidates for classes  Discard candidate which are inappropriate for any reasons  How do we decide which are inappropriate? Object-Oriented Software Systems Engineering – Chapter 4 Slide 20
  • 21. Discarding Candidate Classes  Candidates may be inappropriate for many reasons:  redundant : the same class is given more than one name  vague : cannot tell unambiguously what is meant by a noun  an event or an operation : where noun refers to something which is done to or by the system  an attribute : where the noun refers to something simple with no interesting behaviour  meta-language : where the noun forms part of the way we define things (e.g., requirements, system)  outside the scope of the system : where the noun is relevant to describing how the system works but does not refer to something inside the system Object-Oriented Software Systems Engineering – Chapter 4 Slide 21
  • 22. Identifying Classes for a Library  Consider the following example  A library contains books and journals. It may have several copies of a given book. Some of the books are for short term loans only. All other books may be borrowed by any library member for three weeks. Members of the library can normally borrow up to six items at a time, but members of staff may borrow up to 12 items at one time. Only members of staff may borrow journals. Object-Oriented Software Systems Engineering – Chapter 4 Slide 22
  • 23. LibraryMember Copy of Book Book {persistent} {persistent} {persistent} CopyID: int 0..1 0..* MemberID : Object 1..* 1 Title: String Publisher: String LoanTime: int Author: String ISBN: int borrowed() TotalCopies: int returned() AvailabelCopies: int updateAvaCopies() reservedCopy() addBook () removeBook() findBook() borrowable() Journal {persistent} MemberOfStaff {persistent} 0..1 0..* addJournal () removeJournal( ) findJournal() Object-Oriented Software Systems Engineering – Chapter 4 Slide 23
  • 24. Examples of Class Diagrams  On the next two slides examples of class diagrams are given  One relating to course management  The other relating to order processing  Study the diagrams to see if you can understand them Object-Oriented Software Systems Engineering – Chapter 4 Slide 24
  • 25. School Department {persistent} {persistent} Chairperson name : Name name : Name 0..1 has address : String address : String PhoneNo : Number PhoneNo : Number 1 1..* 1..* addStudent() addStaff removeStudent() removeStaff getStudent() getStaff getAllStudent() getAllStaff addDepartment() removeDepartment() 1..* assigned to getDepartment() getAllDepartment() own 1..* 1..* member Course 1..* 0..1 {persistent} Academic Staff * name : Name Student {persistent} courseID : Number {persistent} attends teaches name : Name addCourse name : Name 1..* updatCourse * studentID : Number * * getCourse Object-Oriented Software Systems Engineering – Chapter 4 Slide 25
  • 26. School Department {persistent} {persistent} Chairperson name : Name name : Name 0..1 has address : String address : String PhoneNo : Number PhoneNo : Number 1 1..* 1..* addStudent() addStaff removeStudent() removeStaff getStudent() getStaff getAllStudent() getAllStaff addDepartment() removeDepartment() 1..* assigned to getDepartment() getAllDepartment() own 1..* 1..* member Course 1..* 0..1 {persistent} Academic Staff * name : Name Student {persistent} courseID : Number {persistent} attends teaches name : Name addCourse name : Name 1..* updatCourse * studentID : Number * * getCourse Object-Oriented Software Systems Engineering – Chapter 4 Slide 26
  • 27. Order Customer {persistent} {persistent} dateReceived * belong to 1 isPrepaid name : Name number : String address : String price : Money creditRating() : String dispatch() close() 1 Corporate Customer Personal Customer {persistent} {persistent} contactName has creditCard# creditRating creditLimit remind() * billForMonth(bn : Integer) OrderLine {persistent} quantity : Integer refer to 1 price : Money * isSatisfied : Boolean Product Object-Oriented Software Systems Engineering – Chapter 4 Slide 27
  • 28. Realisation  A semantic relationship between classifiers in which one classifier specifies a contract that another classifier guarantees to carry out  semantically a cross between a dependency and generalisation  used in two cases Use case collaboration realizes Order Place order management <<interface>> UserInterface realizes Bank Account Object-Oriented Software Systems Engineering – Chapter 4 Slide 28
  • 29. Realizing use cases - Relationship  Realized in a collaboration  shows an internal implementation dependent solution of a use case in terms of classes & their relationships <<realizes>> Collaboration Use Case <<implements>> <<implements>> <<implements>> Use case description: Class A Class B Class C 1. Insert the coins 2. Choose a drink 3. Deliver a drink Oper1() Oper1() Oper1() 4. E.t.c Oper2() Oper2() Oper2() Oper3() e.t.c Oper3() e.t.c Oper3() e.t.c Object-Oriented Software Systems Engineering – Chapter 4 Slide 29
  • 30. Interfaces in UML • UML has a short hand notation for representing interfaces but does not show the methods associated with the interface BankAccount AccountHolder 1 name:String BankEmployee 1..* 1..* 1 balance:Currency has accountNo:String looksAfter credit(Amount:double) debit(Amount:double) suspend() chargeFee(Amount:double) getBalance();double UserInterface interface administers Object-Oriented Software Systems Engineering – Chapter 4 Slide 30
  • 31. Interfaces in UML • A more detailed representation <<interface>> realises BankAccount UserInterface name:String credit(Amount:long) balance:long debit(Amount:long) accountNo:Int getBalance():long credit(Amount:long) debit(Amount:long) <<uses>> dependency suspend() 1 1..* chargeFee(Amount:long) AccountHolder getBalance();long has Object-Oriented Software Systems Engineering – Chapter 4 Slide 31
  • 32. Dependencies - relationship  Dependency is a using relationship  a change in one thing may effect another  shown as a stereotype e.g. friend  one class takes an object of another class as a parameter  one class accesses a global object of another class  one class calls a class scope method in another class <<friend>>  Example Class A Class B  friend  specifies that source is given special visibility into the target  instanceOf  source object is an instance of the target classifier  instantiate  source creates instances of the target Object-Oriented Software Systems Engineering – Chapter 4 Slide 32
  • 33. Summary In this chapter we have:  Introduced class diagram notation  Discussed how to identify problem domain classes  Discussed the different relationships which exist between classes  Introduced the concept of an Interface Object-Oriented Software Systems Engineering – Chapter 4 Slide 33

Hinweis der Redaktion

  1. 1