OO AandD Overview

download OO AandD Overview

of 45

Transcript of OO AandD Overview

  • 8/12/2019 OO AandD Overview

    1/45

    1

    Object Oriented Analysis andDesign: An Overview

    Balaji Rajagopalan

    Credits: Material for the slides is drawn from a variety of sources including Object Oriented Analysis and

    Design using UML by Ali Bahrami.

  • 8/12/2019 OO AandD Overview

    2/45

  • 8/12/2019 OO AandD Overview

    3/45

    3

    Why OO? Higher level of abstraction

    Seamless transition among different phasesof software development

    Encouragement of good programming(Class carefully delineates interface -whatthe class can do and implementation of that

    interface -How the class does what it does) Promotes reusability

    Note that OO analysis and design does not make OO programminglanguage a requirement for implementation

  • 8/12/2019 OO AandD Overview

    4/45

    4

    The result of using the OO approach is..

    Object-Oriented (OO) systems developmentis a way to develop software by building self-contained modules that can be more easily:

    Replaced

    Modifiedand Reused.

  • 8/12/2019 OO AandD Overview

    5/45

  • 8/12/2019 OO AandD Overview

    6/45

    6

    Object BasicsDefine Objects and classes

    Describe objects methods,attributes and how objects respond tomessages,

    Define Polymorphism, Inheritance,data abstraction, encapsulation, and

    protocol,

    Describe objects relationships,

    Describe object persistence,

    Understand meta-classes.

  • 8/12/2019 OO AandD Overview

    7/45

    7

    What is an object? The term object was first formally utilized in the Simula language to

    simulate some aspect of reality.

    An object is an entity. It knows things (has attributes)

    It does things (provides services or has methods)

  • 8/12/2019 OO AandD Overview

    8/45

    8

    Attributes (Contd.)

    I am a Car.

    I know my color,

    manufacturer, cost,owner and model.

  • 8/12/2019 OO AandD Overview

    9/45

    9

    Attributes (Contd.)I am a Fish.

    I know my date ofarrival and

    expiration.

  • 8/12/2019 OO AandD Overview

    10/45

    10

    It does things (methods)I know how to

    computemy payroll.

  • 8/12/2019 OO AandD Overview

    11/45

    11

    Methods (Contd.)

    I know howto stop.

  • 8/12/2019 OO AandD Overview

    12/45

    12

    What is an object? (Contd.) Attributes or properties describe objects state (data) and

    methods define its behavior.

    Object is whatever an application wants to talk about. For example, Parts and assemblies might be objects of bill of material

    application.

    Stocks and bonds might be objects of financial investment applications.

  • 8/12/2019 OO AandD Overview

    13/45

    13

    Objects In an object-oriented system, everything is an object: numbers, arrays,

    records, fields, files, forms, an invoice, etc. An Object is anything, real or abstract, about which we store data and

    those methods that manipulate the data.

    Conceptually, each object is responsible for itself.

    l A chart object is responsible for things like maintaining its data and labels,and even for drawing itself.

    l A window object is responsible for things like opening, sizing, andclosing itself.

  • 8/12/2019 OO AandD Overview

    14/45

    14

    Two Basic Questions When developing an O-O application, two

    basic questions always arise. What objects does the application need? What functionality should those objects have?

  • 8/12/2019 OO AandD Overview

    15/45

    15

    Objects Attributes and Methods Attributes

    represented by data type.

    They describe objects states. In the Car example the cars attributes are:

    color, manufacturer, cost, owner, model, etc.

    Methods define objects behavior and specify the way in which an Objects

    data are manipulated.

    In the Car example the cars methods are:

    drive it, lock it, tow it, carry passenger in it.

  • 8/12/2019 OO AandD Overview

    16/45

    16

    Objects are Grouped in Classes The role of a class is to define the attributesand methods (the state and behavior) of its

    instances. The class car, for example, defines the

    property color. Each individual car (object) will have a

    value for this property, such as "maroon,"

    "yellow" or "white."

  • 8/12/2019 OO AandD Overview

    17/45

    17

    Employee Class

    Jane object Mark objectJohn object

  • 8/12/2019 OO AandD Overview

    18/45

    18

    A Class is an Object Template, or

    an Object Factory.

    B o e in g A i rp l a n e O b j ec ts(B o e in g in s ta n c e s )

  • 8/12/2019 OO AandD Overview

    19/45

    19

    Class Hierarchy An object-oriented system organizes classes

    into subclass-super hierarchy.

    At the top of the hierarchy are the most

    general classes and at the bottom are the

    most specific

  • 8/12/2019 OO AandD Overview

    20/45

    20

    Class Hierarchy (Contd.) A subclass inherits all of the

    properties and methods (procedures)defined in its superclass.

    Motor Vehicle

    Truck CarBus

  • 8/12/2019 OO AandD Overview

    21/45

    21

    Inheritance

    (programming by extension ) Inheritance is a relationship between classes where

    one class is the parent class of another (derived)class.

    Inheritance allows classes to share and reuse

    behaviors and attributes. The real advantage of inheritance is that we can

    build upon what we already have and,

    Reuse what we already have.

  • 8/12/2019 OO AandD Overview

    22/45

    22

    Inheritance (Contd.)

    F o r d

    Vehicle

    C ar

    M u stan g Ta ur us Thunderbird

    stop (myM ustang)

    I dont know how to stop

    I know how to stop

    stop method is reusable

  • 8/12/2019 OO AandD Overview

    23/45

    23

    Multiple Inheritance OO systems permit a class to inherit from

    more than one superclass. This kind of inheritance is referred to as

    multiple inheritance.

  • 8/12/2019 OO AandD Overview

    24/45

    24

    Multiple Inheritance (Contd.) For example utility vehicle inherits from Car and

    Truck classes.

    MotorVehicle

    Truck Car Bus

    UtilityVehicle

  • 8/12/2019 OO AandD Overview

    25/45

    25

    Encapsulation and Information

    Hiding Information hiding is a principle of hiding internal

    data and procedures of an object.

    Private Protocol

    Public ProtocolMessages

    Data

    Permissible operations

  • 8/12/2019 OO AandD Overview

    26/45

    26

    Encapsulation and Information

    Hiding (Contd.)

    By providing an interface to each object in

    such a way as to reveal as little as possible

    about its inner workings.

    Encapsulation protects the data fromcorruption.

  • 8/12/2019 OO AandD Overview

    27/45

    27

    Protocol Protocol is an interface to the object.

    TV contains many complex components,but you do not need to know about them to

    use it.

  • 8/12/2019 OO AandD Overview

    28/45

    28

    Message Objects perform operations in response to

    messages.

    For example, you may communicate with

    your computer by sending it a message from

    hand-held controller.

  • 8/12/2019 OO AandD Overview

    29/45

    29

    A Case Study - A Payroll Program

    Consider a payroll program that processesemployee records at a small manufacturingfirm. This company has three types of

    employees: 1.Managers: Receive a regular salary.

    2. Office Workers: Receive an hourly wage and

    are eligible for overtime after 40 hours. 3.Production Workers: Are paid according to a

    piece rate.

  • 8/12/2019 OO AandD Overview

    30/45

    30

    Structured Approach

    FOR EVERY EMPLOYEE DO

    BEGIN

    IF employee = manager THEN

    CALL computeManagerSalary

    IF employee = office worker THEN

    CALL computeOfficeWorkerSalary

    IF employee = production worker THEN

    CALL computeProductionWorkerSalary

    END

  • 8/12/2019 OO AandD Overview

    31/45

    31

    What if we add two new types of

    employees?

    Temporary office workers ineligible for

    overtime,

    Junior production workers who receive an

    hourly wage plus a lower piece rate.

  • 8/12/2019 OO AandD Overview

    32/45

    32

    FOR EVERY EMPLOYEE DO

    BEGIN

    IF employee = manager THEN

    CALL computeManagerSalary

    IF employee = office worker THEN

    CALL computeOfficeWorker_salary

    IF employee = production worker THEN

    CALL computeProductionWorker_salary

    IF employee = temporary office worker THEN

    CALL computeTemporaryOfficeWorkerSalary

    IF employee = junior production worker THEN

    CALL computeJuniorProductionWorkerSalary

    END

  • 8/12/2019 OO AandD Overview

    33/45

    33

    An Object-Oriented Approach

    What objects does the application need?

    The goal of OO analysis is to identify objects

    and classes that support the problem domainand system's requirements.

    Some general candidate classes are:Persons

    Places

    Things

  • 8/12/2019 OO AandD Overview

    34/45

    34

    What are some of the

    applications classes? Employee

    Manager

    Office Workers

    Production Workers

  • 8/12/2019 OO AandD Overview

    35/45

    35

    Class Hierarchy

    Identify class hierarchy

    Identify commonality among the classes

    Draw the general-specific class hierarchy.

  • 8/12/2019 OO AandD Overview

    36/45

    36

    Class Hierarchy (Contd.)Employee

    OfficeWorker Manager ProductionWorker

    name

    addresssalary

    SS#

    dataEntry

    ComputePayroll

    printReport

    dataEntry

    ComputePayroll

    printReport

    dataEntry

    ComputePayroll

    printReport

  • 8/12/2019 OO AandD Overview

    37/45

    37

    OO Approach

    FOR EVERY EMPLOYEE DO

    BEGIN

    employee computePayroll

    END

    If t f l dd d

  • 8/12/2019 OO AandD Overview

    38/45

    38

    If new types of employees were added

    E m p l o y e e

    O f f ic e W o r k e r M a n a g e r P r o d u c t io n W o r k e r

    n a m e

    a d d r e s s

    s a l a r y

    S S #

    d a t a E n t r y

    C o m p u t e P a y r o l l

    p r in tR e p o r t

    d a t a E n t r y

    C o m p u t e P a y r o l l

    p r in tR e p o r t

    d a t a E n t r y

    C o m p u t e P a y r o l l

    p r in tR e p o r t

    T e m p o r a r y O f f i c e W o r k e r

    C o m p u t e P a y r o l l

    J u n i o r P r o d u c t i o n W o r k e r

    C o m p u t e P a y r o l l

  • 8/12/2019 OO AandD Overview

    39/45

    39

    Polymorphism

    Polymorphism means that the same

    operation may behave differently on

    different classes.

    Example: computePayroll

  • 8/12/2019 OO AandD Overview

    40/45

    40

    Associations

    The concept of association represents

    relationships between objects and classes.

    For example a pilot can flyplanes.

  • 8/12/2019 OO AandD Overview

    41/45

    41

    Associations (Contd.)

    Pilot Planescan fly flown by

  • 8/12/2019 OO AandD Overview

    42/45

    42

    Clients and Servers

    A special form of association is a client-

    server relationship.

    This relationship can be viewed as one-way

    interaction: one object (client) requests theservice of another object (server).

  • 8/12/2019 OO AandD Overview

    43/45

    43

    Clients and Servers (Contd.)

    PrintServer ItemRequest for printing

  • 8/12/2019 OO AandD Overview

    44/45

    44

    Objects and Persistence

    Objects have a lifetime.

    An object can persist beyond application

    session boundaries, during which the object

    is stored in a file or a database, in some fileor database form.

  • 8/12/2019 OO AandD Overview

    45/45

    45

    Summary Rather than treat data and procedures separately, object-oriented

    programming packages them into "objects." O-O system provides you with the set of objects that closely reflects

    the underlying application

    Advantages of object-oriented programming are:

    The ability to reuse code,

    develop more maintainable systems in a shorter amount of time.

    more resilient to change, and

    more reliable, since they are built from completely tested anddebugged classes.