UML - Class Diagrams Operations by undul855

VIEWS: 8 PAGES: 14

									                                     Staffordshire
UML - Class Diagrams                 University

Operations                           School of Computing




 Sofar we have found potential classes, identified
 some associations and assigned attributes to
 classes
 Thissession we will identify operations and decide
 in which class they should be placed
 Decisionsmade in this session should be
 considered a „work in progress‟ – things may
 change later!

  J. Westlake & K.Ingram   1                         Nov 2002
                                        Staffordshire
Identify                                University

Operations(Methods)                     School of Computing


  Operations   are functions (procedures) that may be
    applied to or by objects in a class
  Each   operation is its class‟s contribution to
    achieving a whole Use Case (i.e. a whole Use Case
    will need several operations in several classes)
  A   method is the word used for the implementation
    (i.e. the code) of an operation for a class
  An  operation is always invoked by a call/message
    from elsewhere

 J. Westlake & K.Ingram    2                            Nov 2002
                                        Staffordshire
                                        University

Finding the Operations - 1              School of Computing




 Tostart at a simple level, look at each attribute for
 a class and identify what activities/events cause
 the attribute to be:
  Created

  Read/displayed

  Updated

  Deleted



 J. Westlake & K.Ingram    3                            Nov 2002
                                                  Staffordshire
                                                  University

Finding the Operations - 1                        School of Computing




 E.g.if a video rental shop‟s Member class has
 attributes of ID No, Name, Address, Status then:
   AddNewMember           may create the object
   CheckMemberID          may read all details
   MemberDetailsChange          may update Address
   etc




  J. Westlake & K.Ingram         4                                Nov 2002
                                     Staffordshire
                                     University

Finding the Operations - 1           School of Computing




 Itmay be that a class collaborates with others in
  order to achieve the AddNewMember operation –
  this may mean that a class only needs an
  operation to „set‟ the attributes to their new
  values e.g. a setName operation and a
  setAddress operation
 Similarly,a class may need „get‟ operations for
  some attributes e.g. getName and getAddress

  J. Westlake & K.Ingram   5                         Nov 2002
                                     Staffordshire
                                     University

Finding the Operations - 1           School of Computing




 Always try to place operations in the same class
 as the data which they use (e.g. update/access)
 Wherethere is a choice of class in which to place
 an operation, choose the class which minimises
 the amount of message-passing




 J. Westlake & K.Ingram   6                          Nov 2002
                                       Staffordshire
                                       University

Finding the Operations - 2             School of Computing




 The initial method of getting and setting attributes
 could be described as “a class is responsible for
 getting and setting the values of its attributes”
    second method focuses on a class‟s
 The
 Responsibilities




 J. Westlake & K.Ingram   7                            Nov 2002
                                          Staffordshire
                                          University

Finding the Operations - 2                School of Computing




 What   does this class need to know? – the answer
 is its list of attributes
 What  does this class need to do? – the answer is
 its list of operations
 Operations         = Responsibilities




  J. Westlake & K.Ingram         8                        Nov 2002
                                       Staffordshire
                                       University

Finding the Operations - 2             School of Computing




 Itmay not make sense to say in English „a
  StaffMember calculates their own salary‟
 But if PayRate is an attribute of StaffMember, and if
  CalculatePay has to be done in the system, then it
  makes sense to put the CalculatePay operation in
  the class holding the PayRate
 There may be choices as to where to put the
  operation to be with attributes it uses

  J. Westlake & K.Ingram   9                           Nov 2002
                                      Staffordshire
                                      University

Finding the Operations - 3            School of Computing




 Role    play can help!
 Each developer takes the „role‟ of a class and
 therefore has the information stored in its
 attributes
 Work out the sequence of who has to collaborate
 with who to achieve the required outcome



  J. Westlake & K.Ingram   10                         Nov 2002
                                             Staffordshire
                                             University

Finding the Operations - 3                   School of Computing




 Each     request to another class generates:
   The     responsibility of asking (in the requesting class)
   The  responsibility of doing something (in the
     recipient class)
There is no need to show a responsibility of the
 recipient to reply.



  J. Westlake & K.Ingram       11                            Nov 2002
                                               Staffordshire
                                               University

Inheritance                                    School of Computing




 Specialised         classes inherit from Generalised
 classes
 Operations         are inherited as well as attributes
 Moreoperations can exist in the Specialised class
 than were in the Generalised class
A Specialised class can over-ride inherited
 operations (I.e. have the same operation name
 which does something differently) - Polymorphism

  J. Westlake & K.Ingram         12                            Nov 2002
                                                      Staffordshire
                                                      University

Summary                                               School of Computing




    Operations are activities
    Allocate operations to classes by:
     1.   Get and Set operations
     2.   Identifying Responsibilities
     3.   Using Role Play to assist in placing responsibilities in correct
          classes
    Aim to spread operations across the classes
    Operations are inherited by specialised classes
    Things may be changed when we look at Sequence
     Diagrams later 

    J. Westlake & K.Ingram            13                              Nov 2002
                                          Staffordshire
                                          University
Test Yourself……                           School of Computing
all answers were given during the class


1.    What is meant by an „Operation‟ of a class?
2.    What is meant by „classes must co-operate to
      achieve a Use Case‟?
3.    How do we decide in which class to place an
      operation?
4.    What is meant by „encapsulation‟?
5.    What is meant by „message passing‟?
6.    What is the difference between private and public
      operations?
     J. Westlake & K.Ingram     14                        Nov 2002

								
To top