Cancel Rent Templates by bpa71596


More Info
									Object Oriented Analysis &
     Design (OOAD)

•   It focuses on objects where system is broken
    down in terms of the objects that exist within it.

•   Functions (behaviour) and data (state) relating
    to a single object are self-contained or
    encapsulated in one place.

• Object is an abstraction of something in a
  problem domain, reflecting the capabilities
  of the system to keep information about it,
  interact with it, or both.
• Objects are entities in a software system
  which represent instances of real-world and
  system entities

   Object           Identity        Behaviors           State

An employee   “Mr. John”         Join(),           Joined,
                                 Retire()          Retired.
A book        “Book with title   AddExemplar,      Rent,
              Object Oriented                      available,
              Analysis Design”                     reserved
A sale        “Sale no 0015,     SendInvoiced(),   Invoiced,
              15/12/98”          Cancel().         cancelled.

               Object Class
• Class is a description of a set of objects that
  share the same attributes, operations,
  methods, relationship and semantics.
• Object classes are templates for objects.
  They may be used to create objects.
• An object represents a particular instance of
  a class.

            Term of objects
• Attribute: data items that define object.
• Operation: function in a class that combine
  to form behavior of class.
• Methods: the actual implementation of
  procedure (the body of code that is executed
  in response to a request from other objects
  in the system).

          Employee object & class
Class                               Object
          Employee                  Employee16
 name: string                       name: John
 address: string                    address: M Street No.23
 dateOfBirth: Date                  dateOfBirth: 02/10/65
 employeeNo: integer                employeeNo: 324
 socialSecurityNo: string           socialecurityNo:E342545
 department: Dept                   department: Sale
 ma nager: Employee                 manager: Employee1
 salary: integer                    salary: 2340
 status: {current, left, retired}   stauts:current
 taxCode: integer                   taxCode: 3432
 . ..                               ….
 join ()                            Eployee16.join(02/05/1997)
 leave ()
 retire ()                          Eployee16.retire(03/08/2005)
 changeDetails ()                   Eployee16.changeDetail(“X
                                    Street No. 12”)
 Encapsulation and Data Hiding
• Packaging related data and operations
  together is called encapsulation.
• Data hiding: hides the internal data from
  external by methods (interface).

 private attributes and methods are encapsulated within the
  class, they cannot be seen by clients of the class
 public methods define the interface that the class provides
  to its clients
                              - numCustomers = 0
   private attributes        - MIN_BUDGET = 200
                                  - name: String
                                - address: String
                                   - budget: int

      public methods      + printNumCustomer( ): void
                              + placeOrder( ): void

                               Customer class
        Object communication
• Objects communicate with each other by sending
  – a message is a method call from a message-sending
    object to a message-receiving object
  – a message consists of
     • an object reference which indicates the message receiver
     • a method name (corresponding to a method of the receiver),
     • parameters (corresponding to the arguments of the calling
  – a message-receiving object is a server to a message-
    sending object, and the message-sending object is a
    client of the server
                 Message Passing

     name = “Alex”                                   name = “Lawrence”
                          takeOrder(“sofa”, name,
     address =                                       employeeNo =15
                             address, “120799”)
       “1 Robinson Rd”                               commission = 200
     budget = 2000
    placeOrder( ): void                              takeOrder( ): int
                                return value
          alex                                          lawrence

    lawrence.takeOrder(“sofa”, “1 Robinson Rd”, “120799”)

object reference    method name                parameters

                   Message Passing

        Customer                              SalesPerson
  - numCustomers = 0
                                          - MAX_ PRICE = 200
 - MIN_BUDGET = 200
                                               - name: String
      - name: String
                                           - employeeNo: String
    - address: String
                                              - commission: int
       - budget: int

+ printNumCustomer( ): void               + takeOrder( ): void
    + placeOrder( ): void

          alex                                 lawrence

         client                                   server         12
• Object classes may inherit attributes and
  services from other object classes.
• Inheritance represents the generalization of
  a class.

A generalisation hierarchy

       Ma nager                        Programmer

  budgetsControlled                   project

  Project           De pt.             Strategic
 Ma nag er         Ma nager            Ma nag er
projects          dept              responsibilities

                                      Library Item
                                  Catalogue Number
                                  Acquisition date
                                                                      Library class
                                  Number of copies
                                  Acquire ()
                                  Catalogue ()
                                  Dispose ()
                                  Issue ()
                                  Return ()

              Published item                                 Recorded item
            Title                                           Title
            Publisher                                       Medium

     Book                  Magazine                  Film                Computer
Author                  Year                 Director
Edition                 Issue                Date of release          Version
Publication date                             Distrib                  Platform
                 Libr ary user            User class hierarchy
              Registration #
              Register ()
              De-r egister ()

     Reader                                   Borrower
Affiliation                              Items on loan
                                         Max. loans

                                 Staff                   Student
                         Department                 Major subject
                         Department phone           Home address

          Multiple inheritance
• Rather than inheriting the attributes and services
  from a single parent class, a system which
  supports multiple inheritance allows object classes
  to inherit from several super-classes
• Can lead to semantic conflicts where
  attributes/services with the same name in different
  super-classes have different semantics
• Makes class hierarchy reorganisation more
 Multiple inheritance
     Book                         Voice recording
Author                            Speaker
Edition                           Duration
Publication date                  Recording date

                   Talking book
               # Tapes

     Advantages of inheritance
• It is an abstraction mechanism which may
  be used to classify entities
• It is a reuse mechanism at both the design
  and the programming level
• The inheritance graph is a source of
  organisational knowledge about domains
  and systems

     Problems with inheritance
• Object classes are not self-contained. they cannot
  be understood without reference to their super-
• Designers have a tendency to reuse the inheritance
  graph created during analysis. Can lead to
  significant inefficiency
• The inheritance graphs of analysis, design and
  implementation have different functions and
  should be separately maintained
          Inheritance and OOD
• There are differing views as to whether
  inheritance is fundamental to OOD.
   – View 1. Identifying the inheritance hierarchy or
     network is a fundamental part of object-oriented design.
     Obviously this can only be implemented using an
   – View 2. Inheritance is a useful implementation concept
     which allows reuse of attribute and operation
     definitions. Identifying an inheritance hierarchy at the
     design stage places unnecessary restrictions on the
• Inheritance introduces complexity and this is
  undesirable, especially in critical systems
          Objects Association
• Modeling an association between two classes
  means that there is some sort of relationship
  between objects of each class that may be

     Student                           Course
               0..*             1..*

          Object aggregation
• Aggregation model shows how classes
  which are collections are composed of other

• Similar to the part-of relationship in
  semantic data models

               Object aggregation
                                                         Study pack
                                                   Course title

                                             1             1   1             1

                1 ..*                            1 ..*               1 ..*               0 ..*

               Assignment            OHP slides                      Lectur e      Videotape
             Credits                Slides                         Text
                                                                                 Tape ids.

      1                  1

     1 ..*              1 ..*
  Exercises                  Solutions
#Problems               Text
 Description            Diagrams

   Object Cohesion & Coupling
• Cohesion of a component is a measure of how
  well it fits together. Each operation provides
  functionality which allows the attributes of the
  object to be modified, inspected or used as a basis
  for service provision.
• Coupling is an indication of the strength of
  interconnections between program units. Highly
  coupled systems have strong interconnections,
  with program units dependent on each other
  (shared variables, interchange control function).
  Loosely coupled system which are independent .

        • the ability of different objects to perform the
          appropriate method in response to the same
          message is known as polymorphism.
        • the selection of the appropriate method depends
          on the class used to create the object
                            Shape   getName( )
                                    calculateArea( )

          radius                                  side
                   Circle             Square
calculateArea( )                                  calculateArea( )

          Example Polymorphism
 class Shape {
   private String name;
   public Shape(String aName) { name=aName; }
   public String getName( ) { return name; }
   public float calculateArea( ) { return 0.0f; }
 } // End Shape class                               a generic action
class Circle extends Shape {
  private float radius;
  public Circle(String aName) { super(aName); radius = 1.0f; }
  public Circle(String aName, float radius) {
    super(aName); this.radius = radius;
  }                                       overloading
  public float calculateArea() { return (float)3.14f*radius*radius; }
} // End Circle class

class Square extends Shape {
  private float side;
  public Square(String aName) { super(aName); side =
   1.0f; }
  public Square(String aName, float side) {
    super(aName); this.side = side;
  public float calculateArea() { return (float)
   side*side; }
} // End Square class

              Polymorphism Example
public class ShapeDemoClient {
  public static void main(String argv[ ]) {
    Shape   c1 = new Circle("Circle C1");
    Shape   c2 = new Circle("Circle C2", 3.0f);
    Shape   s1 = new Square("Square S1");
    Shape   s2 = new Square("Square S2", 3.0f);
                                                  rule of subtype
    Shape   shapeArray[ ] = {c1, s1, c2, s2};
    for (int i = 0; i < shapeArray.length; i++) {
      System.out.println("The area of " + shapeArray[i].getName( )
                         + " is " + shapeArray[i].calculateArea( )
                         + " sq. cm.");
    }                                             dynamic binding
  } // End main
} // End ShapeDemoClient1 class

        OO Analysis and Design
OO Analysis - examines requirements from the perspective
 of the classes and objects found in the vocabulary of the
 problem domain. In other words, the world (of the system)
 is modelled in terms of objects and classes.

OO Design - OO decomposition and a notation for depicting
 models of the system under development. Structures are
 developed whereby sets of objects collaborate to provide
 the behaviours that satisfy the requirements of the problem.

       Object Oriented Analysis
•   Analyze the domain problem
•   Describe the process systems
•   Identify the objects
•   Specify attributes
•   Defining operations
•   Inter-object Communication

               Identifying Object
• Objects can be:
   – External Entity (e.g., other systems, devices, people)
     that produce or consume information to be used by
   – Things (e.g., reports, displays, letters, signals) that are
     part of information domain for the problem
   – Places (e.g., book‟s room) that establish the context of
     the problem and the overall function of the system.
   – Organizational units (e.g., division, group, team,
     department) that are relevant to an application,
   – Transaction (e.g., loan, take course, buy, order).

     Example of candidate objects
Just a Line management wishes to increase security, both in their building and on
    site, without antagonizing their employees. They would also like to prevent
    people who are not part of the company from using the Just a Line car park.
It has been decide to issue identity cards to all employees, which they are expected
    to wear while on the Just a Line site. The cards records the name, department
    and number of the member of staff, and permit access to the Just a Line car
A barrier and a card reader are placed at the entrance to the car park. The driver of
    an approaching car insert his or her numbered card in the card reader, which
    then checks that the card number is known to the Just a Line system. If the
    card is recognized, the reader sends a signal to raise the barrier and the car is
    able to enter the car park.
At the exit, there is also a barrier, which is raised when a car wishes to leave the
    car park.
When there are no spaces in the car park a sign at the entrance display “Full” and
    is only switched off when a car leaves.
Special visitor‟s cards, which record a number and the current date, also permit
    access to the car park. Visitor‟s cards may be sent out in advance, or collected
    from reception. All visitor‟s cards must be returned to reception when the
    visitor leaves Just a Line.
              Candidate objects:
Just a Line   management        security    building
site          employee          people      company
car park      card              name        department
number        member of staff   access      barrier
card reader   entrance          driver      car
system        signal            exit        space
sign          visitor           reception

      Candidate objects‟ rejection
• duplicates: if two or more objects are simply different names for the
  same thing.
• irrelevant: objects which exists in the problem domain, but which are
  not intended.
• vague: when considering words carefully it sometimes becomes clear
  that they do not have a price meaning and cannot be the basis of a
  useful in the system.
• general: the meaning is too broad.
• attributes: as the attribute of objects.
• associations: actually represents the relationships between objects.
• roles: sometimes objects referred to by the role they play in a
  particular part of the system.

  Rejected Candidate objects
Candidate objects              Rejection criteria
Just a Line, member of staff   duplicates with company,
                               employee respectively
management,company,            irrelevant to the system
building, site, visitor and
security, people               vague
system                         too general
name, department,              attribute
access                         association
driver                         role

              Rest Objects
Car park       Staff Card   Visitor‟s card
Employee       Entrance     exit
card reader    barrier      Full sign
space          sensor       car

Define class attributes
 Car Park       Full sign
 capacity       on:boolean
 spaces         switch on()
 inc.spaces()   switch off()
 space left()

   Barrier      Card Reader
   type:        valid card nos.
   up:boolean   read card()
   raise()      card OK()

                    Data Dictionary
Barrier: type + up
   type = [“Entrance”|”Exit”]
   up = [“true”|”false”]

   raise: if the barrier is not already raised, this operation takes as
   argument an object of the barrier class and returns an object of the
   same class, with the up attribute set to “true”. If the barrier is already
   up, the operation returns the error message “barrier is already raised”

   lower: if the barrier is not already lower, this operation takes as
   argument an object of the barrier class and returns an object of the
   same class, with the up attribute set to “false”. If the barrier is already
   down, the operation returns the error message “barrier already
          Objects Relationship
                Car Park                                   Car Park

2 ..*                                          1 ..*
               2 ..*
Barrier                                 Card Reader
                                                1 .. *

                                        Valid cards

                                                  1 .. *


                       Visitor‟s Card                       Staff Card

    Object behaviour modelling
• A behavioural model shows the interactions
  between objects to produce some particular
  system behaviour that is specified as a use-
• Sequence diagrams (or collaboration
  diagrams) in the UML are used to model
  interaction between objects

   Sequence Diagram for Entrance
:User   :CarPark       :Sensor    :CardReader                :Valid card   :Barrier     :Full Sign
                                 Full Sign off

               Car present

             Check space left

        Card number
                                                 Card number

                                                  Card OK
             Card returned

                                                 Car not present

                                  Decrement Space

              Check space left

                Yes                                                                        42
      OO Analysis and Design
Object-Oriented (OO) development is very different
 from structured development:

• Structured approach focuses on major functions
  within a system and on the data used by the

• OO approach focuses on the objects in a system
  and on the relationships between those objects.
 Unlike functional decomposition, OO views a
  complex problem as a meaningful collection of
  objects that collaborate to achieve some higher
  level behaviour => closely mirrors how people
  view complex problems => using OO should
  make the job of developing large, complex
  systems more manageable.

Object Oriented Model

Structured Model

OO:                               Structured:
Systems decomposed into           Systems decomposed into
collections of data objects;      functions; functions and data
function + data in one place =>   modelled separately =>
• System components more          • System components are more
  independent => more resilient     dependent on each other =>
  to requirements and               requirements and
  maintenance changes.              maintenance changes more
• Inheritance and polymorphism      difficult
  are possible => reuse,          • Inheritance and polymorphism
  extension, and tailoring of       not possible => limited reuse
  software/designs is possible.     possible.
• Closely mirrors how humans      • System components do not
  decompose and solve               map closely to real-world
  complex.                          entities => difficult to manage
OO:                                Structured:
Process allows for iterative and   Process less flexible and largely
incremental development =>         linear =>
• Integration of programs is       • Integration of programs is „big
  series of incremental               bang‟ effect.
  prototypes.                      • Users or developers provided
• Users and developers get            with little or no feedback; see
  important feedback                  system only when it has been
  throughout development.             completed.
• Testing resources distributed    • Testing resources are
  more evenly.                        concentrated in the
• If time is short, coding and        implementation stage only.
  testing can begin before the     • Coding and testing cannot
  design is finished.                 begin until all previous stages
                                      are complete.            48

To top