ooad, classes, objects

Upload: thomas-johnson

Post on 03-Jun-2018

255 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/12/2019 OOAD, Classes, Objects

    1/147

    Identifying use cases

    Object Analysis

    Classification

    Identifying Object relationships

    Attributes and Methods.

  • 8/12/2019 OOAD, Classes, Objects

    2/147

    Agenda

    Identifying Use Cases

    Object Analysis: Classification

    Identifying object relationships, Attributesand Methods.

  • 8/12/2019 OOAD, Classes, Objects

    3/147

    1.Object oriented analysis

    Process: Identifying Use cases

  • 8/12/2019 OOAD, Classes, Objects

    4/147

    Identifying the use cases: Goals

    The use-case approach to object-oriented

    analysis and the object-oriented analysis

    process.

    Identifying actors.

    Identifying use cases.

    Documentation.

  • 8/12/2019 OOAD, Classes, Objects

    5/147

    What Is Analysis?

    Analysis is the process of transforminga problem definition from a fuzzy set of

    facts and myths into a coherent

    statement of a systems requirements.

  • 8/12/2019 OOAD, Classes, Objects

    6/147

    Analysis

    The main objective of the analysis is to

    capture:

    a complete, unambiguous, and consistent

    picture of the requirements of the systemand

    what the system must do to satisfy the

    users' requirements and needs.

  • 8/12/2019 OOAD, Classes, Objects

    7/147

  • 8/12/2019 OOAD, Classes, Objects

    8/147

    Requirements Difficulties

    Three most common sources ofrequirements difficulties are:

    1. Incomplete requirements.

    2. Fuzzy descriptions (such as fastresponse).

    3. Unneeded features.

  • 8/12/2019 OOAD, Classes, Objects

    9/147

    The Object-Oriented Analysis

    (OOA) Process The process consists of the following

    steps:

    1. Identify the actors:

    Who is using the system?

    Or, in the case of a new system, who will be

    using system?

  • 8/12/2019 OOAD, Classes, Objects

    10/147

  • 8/12/2019 OOAD, Classes, Objects

    11/147

    The OOA Process (Cont)

    3. Develop the use case: What the users are doing with the system?

    Or, in the case of a new system, what

    users will be doing with the system?

    Use cases provide us with comprehensivedocumentation of the system under study.

  • 8/12/2019 OOAD, Classes, Objects

    12/147

  • 8/12/2019 OOAD, Classes, Objects

    13/147

    The OOA Process (Cont)

    5. Classificationdevelop a static UML

    class diagram:

    Identify classes.

    Identify relationships.

    Identify attributes.

    Identify methods.

  • 8/12/2019 OOAD, Classes, Objects

    14/147

    The OOA Process (Cont)

    6. Iterate and refine: If needed, repeatthe preceding steps.

    Refineand

    iterateIdentify Actors

    Develop Use-Cases, ADs

    DevelopInteraction

    Diagrams

    Identify Classes,Relationships,

    Attributes &Methods

    O-O Analysis

    prototyping

  • 8/12/2019 OOAD, Classes, Objects

    15/147

    Developing Business Processes

    Developing an activity diagram of the

    business processes can provide us with

    an overall view of the system.

  • 8/12/2019 OOAD, Classes, Objects

    16/147

    Use Case Model

    Use cases are scenarios for understandingsystem requirements.

    The use-case modeldescribes the uses ofthe system and shows the courses of events

    that can be performed. Some Definitions

    User Human Users + Other Systems

    Use Case A piece of functionality

    Use-Case Model All the use cases

    Use-Case Driven Developmentprocess follows a flow

  • 8/12/2019 OOAD, Classes, Objects

    17/147

    Use case DrivenCapture the users needs (requirements - in users context)

    - Helps in Project Scheduling

    Analyse to specify the needs

    Design to realize the needs

    Implement to implement the needs

    Test to verify the needs

    Use cases Test

    Test1

    Test2

    Test3

    Verified by

    Implementation

    Implemented by

    Design

    Design2

    Design1

    Design3

    Design4

    Realized by

    Analysis

    Specified by

    Product development is Use case driven:

  • 8/12/2019 OOAD, Classes, Objects

    18/147

    Use Case Model (Cont)

    Use case defines what happens in the

    system when a use case is performed.

    The use-case model tries tosystematically identify uses of the

    system and therefore the system's

    responsibilities.

  • 8/12/2019 OOAD, Classes, Objects

    19/147

    Use Cases Under the

    Microscope "A Use Caseis a sequence of

    transactionsin a systemwhose task is

    to yield results of measurable valueto

    an individual actorof the system."

    What is a

    Use Case

    again?

  • 8/12/2019 OOAD, Classes, Objects

    20/147

    Use Case Key Concepts

    Use case.Use caseis a special flow of

    events through the system.

    Actors.An actor is a user playing a role

    with respect to the system.

    In a system.This simply means that the

    actors communicate with the system's

    use case.

  • 8/12/2019 OOAD, Classes, Objects

    21/147

    Use Case Key Concepts

    (Cont)

    A measurable value.A use case musthelp the actor to perform a task that has

    some identifiable value.

    Transaction.A transaction is an atomicset of activities that are performed either

    fully or not at all.

  • 8/12/2019 OOAD, Classes, Objects

    22/147

    Use Associations

    The useassociation occurs when you

    are describing your use cases and

    notice that some of them have commonsubflows.

    The useassociation allows you to

    extract the common subflow and make

    it a use case of its own.

  • 8/12/2019 OOAD, Classes, Objects

    23/147

    Extends Associations

    The extendsassociationis used when

    you have one use case that is similar to

    another use case but does a bit more or

    Is more specialized; in essence, it is likea subclass.

  • 8/12/2019 OOAD, Classes, Objects

    24/147

    Library

    Borrow books

    Reading booksNewspaper

    Member

    Supplier

    Purchasing Supplies

    Inter library loan

    extends

    uses

    uses

    Performing research

    Return Books

    Circulation Clerk

    Checking Library Card

  • 8/12/2019 OOAD, Classes, Objects

    25/147

    Fully Developed

    Use Case Description

    Use Case Name: Checkout Movies

    Scenario: Checkout movies at counter

    Triggering Event: Customer brings movies to checkout counter

    Brief Description: When customer brings movies to counter, clerk checks membership ID,

    clerk scans in each movie identifier, takes payment, and notifies

    customer of return due date and time.

    Actors: Video clerk

    Related Use

    Cases:

    Add new member

    Stakeholders: Clerk, Store manager

    Preconditions: Movie titles must existMovie copy must exist

    Customer must exist (or Add new member must be invoked)

    Postconditions: Video Rental and rental line items must be created

    Payment transaction must be created

    Status of movie copy must be updated

    Video Rental must be connected to customer family member

  • 8/12/2019 OOAD, Classes, Objects

    26/147

    Use Case Diagram NotationActor

    Association

    Use Case

    Use case with Extension points

  • 8/12/2019 OOAD, Classes, Objects

    27/147

    Types of Use Cases

    Use cases could be viewed as concrete

    or abstract.

    An abstractuse caseis not completeand has no initiation actors but is used

    by a concreteuse case, which does

    interact with actors.

  • 8/12/2019 OOAD, Classes, Objects

    28/147

    Identifying the Actors

    The term actorrepresents the role auser plays with respect to the system.

    When dealing with actors, it is important

    to think about roles rather thanpeople or job titles.

  • 8/12/2019 OOAD, Classes, Objects

    29/147

    Identifying the Actors (Cont)

    Candidates for actors can be foundthrough the answers to the following

    questions:

    Who is using the system? Or, Who is affected by the system? Or,

    Which groups need help from the system

    to perform a task?

  • 8/12/2019 OOAD, Classes, Objects

    30/147

    Identifying the Actors (Cont)

    Who affects the system? Or, Which user groups are needed by the

    system to perform its functions? These

    functions can be both main functions and

    secondary functions, such as

    administration.

    Which external hardware or other systems

    (if any) use the system to perform tasks?

  • 8/12/2019 OOAD, Classes, Objects

    31/147

    Identifying the Actors (Cont)

    What problems does this application solve

    (that is, for whom)?

    And, finally, how do users use the system

    (use case)? What are they doing with thesystem?

    Guidelines for Finding Use

  • 8/12/2019 OOAD, Classes, Objects

    32/147

    Guidelines for Finding Use

    Cases

    For each actor, find the tasks andfunctions that the actor should be able

    to perform or that the system needs the

    actor to perform. Name the use cases.

    Describe the use cases briefly by

    applying terms with which the user isfamiliar.

  • 8/12/2019 OOAD, Classes, Objects

    33/147

    Separate Actors From Users

    Each use case should have only onemain actor.

    Isolate users from actors.

    Isolate actors from other actors(separate the responsibilities of each

    actor).

    Isolate use cases that have differentinitiating actors and slightly different

    behavior.

  • 8/12/2019 OOAD, Classes, Objects

    34/147

  • 8/12/2019 OOAD, Classes, Objects

    35/147

    Effective Documentation:

    Common Cover

    All documentsshould share a common

    cover sheet that identifies the

    document, the current version, and the

    individual responsible for the content.

  • 8/12/2019 OOAD, Classes, Objects

    36/147

    80 -20

    8020 Rule

    80 percent of the work can be done with 20percent of the documentation.

    The trick is to make sure that the 20 percent

    is easily accessible and the rest (80 percent)is available to those (few) who need to

    know.

  • 8/12/2019 OOAD, Classes, Objects

    37/147

    Familiar Vocabulary

    Use a vocabulary that your readers

    understand and are comfortable with.

    The main objective here is to

    communicate with readers and do notimpress them with buzz words.

  • 8/12/2019 OOAD, Classes, Objects

    38/147

    Make the Document as Short as

    Possible

    Eliminate all repetition;

    Present summaries, reviews,

    organization chapters in less than three

    pages;

    Make chapter headings task

    oriented so that the table of

    contents also could serve as

    an index.

  • 8/12/2019 OOAD, Classes, Objects

    39/147

    Organize the Document

    Use the rules of good organization

    (such as the organization's standards,

    college handbooks, Strunk and White's

    Elements of Style, or the University ofChicago Manual of Style) within each

    section.

  • 8/12/2019 OOAD, Classes, Objects

    40/147

    Summary

    The main objective of the analysis is tocapture a complete, unambiguous, and

    consistent picture of the requirements of

    the system. Construct several models and views of

    the system to describe what the system

    does rather than how.

  • 8/12/2019 OOAD, Classes, Objects

    41/147

    Summary (Cont)

    Capturing use cases is one of the first

    things to do in coming up with

    requirements.

    Every use case is a potential requirement.

  • 8/12/2019 OOAD, Classes, Objects

    42/147

    Summary (Cont)

    The key in developing effective

    documentation is to eliminate all

    repetition; present summaries, reviews,

    organization chapters in less than three

    pages.

    Use the 8020 rule: 80 percent of the

    work can be done with 20 percent of the

    documentation.

  • 8/12/2019 OOAD, Classes, Objects

    43/147

    Object Analysis: Classification

  • 8/12/2019 OOAD, Classes, Objects

    44/147

    Introduction

    OOA is a process by which we can identify

    classes that play a role in achieving system

    goals and requirements

    Various Approaches for identifying the classes Classification: is the process of checking to see

    if an object belongs to a category or a class, is

    regarded as a basic attribute of human nature.

    Example: Classifying the car

  • 8/12/2019 OOAD, Classes, Objects

    45/147

    What is an Object

    An object Is an unique, identifiable, self-

    contained entity that possesses operations

    and contains attributes

    Possesses all the know-how and informationit needs to perform the services for which it

    was designed

    Is a "black box" which receives and sends

    messages

  • 8/12/2019 OOAD, Classes, Objects

    46/147

    What is a Class ?

    A Class is a software template that defines

    the methods and variables to be included

    in a particular kind of Object.

    Is a blue print used to create objects. As it

    is a blue print, at runtime it will not occupy

    any memory.

    Examples :Animal, Human being, Automobiles

  • 8/12/2019 OOAD, Classes, Objects

    47/147

    Classes VS. ObjectsClass Object

    Class is a type/ template

    for similar objects

    Object is an instance of

    the class

    Class is purely a staticconcept, represented by

    program text

    Objects are run time /dynamic entities that

    occupy space in memory

  • 8/12/2019 OOAD, Classes, Objects

    48/147

    ... Intelligent classification is intellectually

    hard work, and it best comes aboutthrough an incremental and iterative

    process

    Booch

  • 8/12/2019 OOAD, Classes, Objects

    49/147

    ..There is no such thing as the perfect

    class structure, nor the right set ofobjects. As in any engineering

    discipline, our design choice is

    compromisingly shaped by many

    competing factors.

    Booch

  • 8/12/2019 OOAD, Classes, Objects

    50/147

    Point To Remember

    Two Issues

    A class is a specification of structure,

    behavior, and the description of an

    object.

    Classification is more

    concerned with identifying

    classes than identifying theindividual objects ina system.

    Th Ch ll f Cl ifi ti

  • 8/12/2019 OOAD, Classes, Objects

    51/147

    The Challenge of Classification

    Intelligent classification is intellectuallyhard work and may seem rather

    arbitrary.

    Martin and Odell have observed inobject-oriented analysis and

    design, that

    In fact, an object can be categorized inmore than one way.

  • 8/12/2019 OOAD, Classes, Objects

    52/147

    Employer Employee

    Pet Owner Good Credit Risk

    Approaches for Identifying

  • 8/12/2019 OOAD, Classes, Objects

    53/147

    Approaches for Identifying

    Classes The noun phrase approach.

    The common class patterns approach.

    The use-case driven approach.

    The class responsibilities collaboration

    (CRC) approach.

  • 8/12/2019 OOAD, Classes, Objects

    54/147

    Noun Phrase Approach

    Using this method, you have to read

    through the Use cases, interviews, and

    requirements specification carefully,

    looking for noun phrases.

    N Ph St t (C t)

  • 8/12/2019 OOAD, Classes, Objects

    55/147

    Noun Phrase Strategy (Cont)

    Change all plurals to singular and makea list, which can then be divided into

    three categories.

    N Ph St t (C t)

  • 8/12/2019 OOAD, Classes, Objects

    56/147

    Noun Phrase Strategy (Cont)

    It is safe to scrap the Irrelevant Classes.

    You must be able to formulate a

    statement of purpose for each

    candidate class; if not, simply eliminate

    it.

    You must then select candidate classes

    from the other two categories.

  • 8/12/2019 OOAD, Classes, Objects

    57/147

    Guidelines For Identifying

    Classes The followings are guidelines for

    selecting classes in your application:

    Look for nouns and noun phrases inthe problem statement.

    Some classes are implicit or taken from

    general knowledge.

  • 8/12/2019 OOAD, Classes, Objects

    58/147

    G id li F R fi i Cl

  • 8/12/2019 OOAD, Classes, Objects

    59/147

    Guidelines For Refining Classes

    Redundant Classes: Do not keep two classes that express

    the same information.

    If more than one word is being

    used to describe the same idea,

    select the one that is the most

    meaningful in the context of the

    system.

    Guidelines For Refining Classes

  • 8/12/2019 OOAD, Classes, Objects

    60/147

    Guidelines For Refining Classes

    (Cont)Adjective Classes:

    Does the object represented by the noun

    behave differently when the adjective is

    applied to it?

    Guidelines For Refining Classes

  • 8/12/2019 OOAD, Classes, Objects

    61/147

    Guidelines For Refining Classes

    (Cont) If the use of the adjective signals that the

    behavior of the object is different, then

    make a new class.

    For example, IfAdult MembershipandYouth Membershipbehave differently,

    than they should be classified as different

    classes.

  • 8/12/2019 OOAD, Classes, Objects

    62/147

    Guidelines For Refining Classes

  • 8/12/2019 OOAD, Classes, Objects

    63/147

    Guidelines For Refining Classes

    (Cont)

    Irrelevant Classes:

    Each class must have a purpose and

    every class should be clearly defined

    and necessary.

    If you cannot come up with a statement

    of purpose, simply eliminate the

    candidate class.

  • 8/12/2019 OOAD, Classes, Objects

    64/147

    Identifying a list of candidate classes

    Take a coherent, concise statement of therequirement of the system

    Underline its noun and noun phrases, that is,identify the words and phases the denote things

    This gives a list of candidate classes, which wecan then whittle down and modify to get aninitial class list for the system

  • 8/12/2019 OOAD, Classes, Objects

    65/147

  • 8/12/2019 OOAD, Classes, Objects

    66/147

    This leaves:

    Book

    Journal

    Copy (of book)

    Library member

    Member of staff

  • 8/12/2019 OOAD, Classes, Objects

    67/147

    Common Class Patterns Approach

    This approach is based on the knowledge-

    base of the common classes that have

    been proposed by various researchers.

    C did t Cl E t

  • 8/12/2019 OOAD, Classes, Objects

    68/147

    Candidate Classes - Events

    These are points in time that must berecorded and remembered.

    Things happen, usually to something

    else, at a given date and time, or as astep in an ordered sequence.

    For example order which is an

    event that must be remembered.

    C did t Cl O i ti

  • 8/12/2019 OOAD, Classes, Objects

    69/147

    Candidate Classes - Organization

    The organizational units that peoplebelong to.

    For example, accounting department

    might be considered as a potentialclass.

  • 8/12/2019 OOAD, Classes, Objects

    70/147

    C did Cl P l (C )

  • 8/12/2019 OOAD, Classes, Objects

    71/147

    Candidate Classes - People (Cont)

    It can be divided into two types (Coad &

    Yourdon):

    Those representing users of the system,

    such as an operator, or a clerk;

    C did t Cl P l (C t)

  • 8/12/2019 OOAD, Classes, Objects

    72/147

    Candidate Classes - People (Con t)

    Those people who do not use thesystem but about whom information is

    kept.

    Some examples are Client, Employee,Teacher, Manager.

    C did t Cl Pl

  • 8/12/2019 OOAD, Classes, Objects

    73/147

    Candidate Classes - Places

    These are physical locations, such as

    buildings, stores, sites or offices that the

    system must keep information about.

    Candidate Classes - Tangible

  • 8/12/2019 OOAD, Classes, Objects

    74/147

    Candidate Classes Tangible

    Things and Devices

    Physical objects, or group of objects, that

    are tangible, and devices with which the

    application interacts.

    For example, cars, pressuresensors.

  • 8/12/2019 OOAD, Classes, Objects

    75/147

    Candidate Classes - Concepts

    Concepts are principles or

    ideas not tangible but used to

    organize or keep track of

    business activities and/or

    communications.

    Use case Driven Approach

  • 8/12/2019 OOAD, Classes, Objects

    76/147

    Use-case Driven Approach

    Once the system has been described interms of its scenarios, we can examine

    the textual description or steps of each

    scenario to determine what objects areneeded for the scenario to occur.

    U D i A h

  • 8/12/2019 OOAD, Classes, Objects

    77/147

    Use-case Driven Approach

    To identify objects of a system andtheir behaviors, the lowest level of

    executable use cases is further

    analyzed with a sequence and

    collaboration diagram pair.

    By walking through the steps, you can

    determine what objects are necessary

    for the steps to take place.

    Sequence Diagram Notation

  • 8/12/2019 OOAD, Classes, Objects

    78/147

    Sequence Diagram NotationActor

    Class

    Synchronous message

    Asynchronous message

    Return message

    Focus of Control

    lifeline

    Termination

  • 8/12/2019 OOAD, Classes, Objects

    79/147

    Cl ient A T M M a ch in e

    B a d P I N N u m b e r

    B a d P I N N u m b e r M e s s a g e

    E j ec t AT M card

    Re quest take card

    T ake ca rd

    Disp lay main screen

    Ver if y P IN Num ber

    Reques t P IN num ber

    Reques t P IN

    Inser t AT M c ard

    BankCl ient

  • 8/12/2019 OOAD, Classes, Objects

    80/147

    Checking AccountBank Client ATM Machine Account

    Withdraw Checking Account

    Withdraw Successful

    Request Kind

    Enter Kind

    Request Amount

    Enter Amount

    Process Transaction

    Transaction succeed

    Dispense Cash

    Request Take Cash

    Take Cash

    Request Continuation

    Terminate

    Print Receipt

  • 8/12/2019 OOAD, Classes, Objects

    81/147

    ATM Machine:Definition

    Checking Account

    Account Bank Client

    5: Process Transaction

    8: Transaction succeed

    4: Enter Amount

    13: Terminate

    1: Request Kind

    2: Enter Kind

    3: Request Amount

    9: Dispense Cash

    10: Request Take Cash

    11: Take Cash

    12: Request Continuation

    14: Print Receipt

    7: Withdraw Successful 6: Withdraw Checking Account

  • 8/12/2019 OOAD, Classes, Objects

    82/147

    COLLABORATION DIAGRAM

    A Collaboration is a name given to the

    interaction among two or more

    classes\objects. Collaboration Diagram show

    objectsand their links to each other, as well

    as how messages are sent between the linked

    objects.

  • 8/12/2019 OOAD, Classes, Objects

    83/147

    COLLABORATION DIAGRAM

  • 8/12/2019 OOAD, Classes, Objects

    84/147

    COLLABORATION DIAGRAM

    COLLABORATION DIAGRAM -

  • 8/12/2019 OOAD, Classes, Objects

    85/147

    COLLABORATION DIAGRAM

    PURPOSE

    Collaboration Diagrams are useful when

    we want to refer to a particular interaction.

    To illustrate the coordination of object

    structure and flow of control.

    COLLABORATION DIAGRAM VS

  • 8/12/2019 OOAD, Classes, Objects

    86/147

    COLLABORATION DIAGRAM VS

    SEQUENCE DIAGRAM

    Both show the interaction between the

    objects\classes.

    If time is the most important aspect toemphasize, choose sequence diagrams.

    If the role is the most important aspect to

    emphasize, choose collaboration diagram

    CRC Cards

  • 8/12/2019 OOAD, Classes, Objects

    87/147

    CRC Cards

    CRC stands for Class, Responsibilities

    and Collaboratorsdeveloped by

    Cunningham, Wilkerson and Beck.

    CRC can be used for identifying classes

    and their responsibilities.

  • 8/12/2019 OOAD, Classes, Objects

    88/147

    Collaborations

  • 8/12/2019 OOAD, Classes, Objects

    89/147

    Collaborations

    An object can accomplish either acertain responsibility itself, or it may

    require the assistance of other objects.

    If it requires an assistance of otherobjects, it must collaborate with those

    objects to fulfill its responsibility.

    CRC Cards (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    90/147

    CRC Cards (Con t)

    CRC cards are 4" x 6" index cards. Allthe information for an object is written

    on a card.

    ClassName Collaborators...

    ...

    Responsibilities

    CRC Cards (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    91/147

    CRC Cards (Con t)

    CRC starts with only one or two obviouscards.

    If the situation calls for a responsibility not

    already covered by one of the objects:Add, or

    Create a new object to address that

    responsibility.

    Guidelines for Naming Classes

  • 8/12/2019 OOAD, Classes, Objects

    92/147

    Guidelines for Naming Classes

    The class should describe a singleobject, so it should be the singular form

    of noun.

    Use names that the users arecomfortable with.

    The name of a class should reflect its

    intrinsic nature.

    Guidelines for Naming Classes

  • 8/12/2019 OOAD, Classes, Objects

    93/147

    g

    (Cont)

    By the convention, the class name mustbegin with an upper case letter.

    For compound words, capitalize the first

    letter of each word - for example,LoanWindow.

    S mmar

  • 8/12/2019 OOAD, Classes, Objects

    94/147

    Summary Finding classes is not easy.

    The more practice you have, the better

    you get at identifying classes.

    There is no such thing as the right set

    of classes.

    Finding classes is an incremental

    and iterative process.

    Summary (C t)

  • 8/12/2019 OOAD, Classes, Objects

    95/147

    Summary (Con t) Unless you are starting with a lot of

    domain knowledge, you are probablymissing more classes than you will

    eliminate.

    Naming a class is also an importantactivity.

    The class should describe a single

    object, so it should be a singular nounor an adjective and a noun.

  • 8/12/2019 OOAD, Classes, Objects

    96/147

    Identifying ObjectRelationships, Attributes, and

    Methods

    Goals

  • 8/12/2019 OOAD, Classes, Objects

    97/147

    Goals

    Analyzing relationships among classes.

    Identifying association.

    Association patterns.

    Identifying super- and subclass

    hierarchies.

  • 8/12/2019 OOAD, Classes, Objects

    98/147

  • 8/12/2019 OOAD, Classes, Objects

    99/147

    Objects contribute to the behavior of the

    system by collaborating with one

    another.

    Grady Booch

  • 8/12/2019 OOAD, Classes, Objects

    100/147

    In OO environment, an application is

    the interactions and relationships

    among its domain objects.

    All objects stand in relationship to

    others, on whom they rely for services

    and controls.

    Obj t R l ti hi

  • 8/12/2019 OOAD, Classes, Objects

    101/147

    Objects Relationships Three types of relationships among

    objects are:

    Association.

    Super-sub structure(also known as

    generalization hierarchy).Aggregation and a-part-of structure.

    Associations

  • 8/12/2019 OOAD, Classes, Objects

    102/147

    Associations

    A reference from one class to another is anassociation.

    Basically a dependency between two or

    more classes is an association. For example, Jackie

    works forJohn.

  • 8/12/2019 OOAD, Classes, Objects

    103/147

    Guidelines For Identifying

  • 8/12/2019 OOAD, Classes, Objects

    104/147

    Associations

    Association often appears as a verbin a

    problem statement and represents

    relationships between classes.

    For example a pilot can flyplanes.

    Guidelines For Identifying

  • 8/12/2019 OOAD, Classes, Objects

    105/147

    Associations (Cont)

    Association often corresponds to verbor prepositional phrasessuch aspart of,

    next to, works for, contained in, etc.

  • 8/12/2019 OOAD, Classes, Objects

    106/147

    Common Association Patterns

  • 8/12/2019 OOAD, Classes, Objects

    107/147

    Common Association Patterns

    (Con

    t) Communication associationtalk to, orderto.

    For example, a customer places an order

    with an operator person.

    Order

    OperatorCustomer

    Eliminate Unnecessary

  • 8/12/2019 OOAD, Classes, Objects

    108/147

    Eliminate Unnecessary

    Associations Implementation association.Defer

    implementation-specific associations to the

    design phase. Ternary associations. Ternaryor n-ary

    associationis an association among more

    than two classes

    Eliminate Unnecessary

  • 8/12/2019 OOAD, Classes, Objects

    109/147

    Associations (Cont)

    Directedactions(derived)associations

    can be defined in terms of other

    associations.

    Since they are redundant you should avoid

    these types of association.

    Eliminate Unnecessary

  • 8/12/2019 OOAD, Classes, Objects

    110/147

    Associations (Cont)

    Grandparent of Ken can be definedin terms of the parent association.

    John KenGrand Parent

    of

    John BrianParent

    ofKen

    Parent

    of

    Superclass-Subclass

  • 8/12/2019 OOAD, Classes, Objects

    111/147

    p

    Relationships

    Recall that at the top of the class hierarchy

    is the most general class, and from it

    descend all other, more specialized

    classes.

    Sub-classes are more specialized versions

    of their super-classes.

    Guidelines For Identifying Super-

  • 8/12/2019 OOAD, Classes, Objects

    112/147

    sub Relationships: Top-down

    Look for noun phrases composed of

    various adjectives on class name.

    Example, Military Aircraft and Civilian

    Aircraft.

    Only specialize when the sub

    classes have significant behavior.

    Guidelines For Identifying Super-

  • 8/12/2019 OOAD, Classes, Objects

    113/147

    sub Relationships: Bottom-up Look for classes with similar attributes or

    methods.

    Group them by moving the common

    attributes and methods to super class.

    Do not force classes to fit a preconceived

    generalization structure.

    Guidelines For Identifying Super-

  • 8/12/2019 OOAD, Classes, Objects

    114/147

    sub Relationships: Reusability

    Move attributes and methods as high as

    possible in the hierarchy.

    At the same time do not create very

    specialized classes at the top of hierarchy.

    This balancing act can be

    achieved through several

    iterations.

    Guidelines For Identifying Super-sub Relationships: Multiple

  • 8/12/2019 OOAD, Classes, Objects

    115/147

    sub Relationships: Multiple

    inheritance Avoid excessive use of multiple

    inheritance.

    It is also more difficult to understand

    programs written in multiple

    inheritance system.

    Multiple inheritance (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    116/147

    One way to achieve the benefits of multiple

    inheritance is to inherit from the mostappropriate class and add an object of other

    class as an attribute.

    In essence, a multiple inheritance can be

    represented as an aggregation

    of a single inheritance and

    aggregation. This meta

    model reflects thissituation.

    Multiple Inheritance

    Single Inheritance Aggregation

    A-Part-of Relationship -

  • 8/12/2019 OOAD, Classes, Objects

    117/147

    A-Part-of Relationship -

    Aggregation

    A-part-of relationship, also calledaggregation, represents the situation

    where a class consists of several

    component classes.

    A-Part-of Relationship -

    A i (C )

  • 8/12/2019 OOAD, Classes, Objects

    118/147

    Aggregation (Cont)

    This does not mean that the classbehaves like its parts.

    For example, a car consists of many other

    classes, one of them is a radio,but a car does not

    behave like a radio.

    Engine Radio

    Car

    Carburetor

    A-Part-of Relationship -

    A ti (C t)

  • 8/12/2019 OOAD, Classes, Objects

    119/147

    Aggregation (Cont)

    Two major properties of a-part-ofrelationship are:

    transitivity

    antisymmetry

    Transitivity

  • 8/12/2019 OOAD, Classes, Objects

    120/147

    Transitivity

    IfAis part of Band B is part of C, thenAis part ofC.

    For example, a carburetor is part of an

    engine and an engine is part of a car;therefore, a carburetor is part of a car.

    Antisymmetry

  • 8/12/2019 OOAD, Classes, Objects

    121/147

    Antisymmetry

    IfAis part of B, then Bis not part ofA.

    For example, an engine is part of a car,

    but a car is not part of an engine.

    Where responsibilities for

    t i b h i t id ?

  • 8/12/2019 OOAD, Classes, Objects

    122/147

    certain behavior must reside?

    Does the part class belong to problemdomain?

    Is the part class within the system's

    responsibilities?

    where responsibilities ...(Cont)

  • 8/12/2019 OOAD, Classes, Objects

    123/147

    where responsibilities ...(Con t)

    Does the part class capture more than asingle value?

    If it captures only a single value, then

    simply include it as an attribute with thewhole class.

    Does it provide a useful abstraction in

    dealing with the problem domain?

  • 8/12/2019 OOAD, Classes, Objects

    124/147

    A-Part-of Relationship

  • 8/12/2019 OOAD, Classes, Objects

    125/147

    Patterns

    Container

    A case such as course-teacher situation,

    where a course is considered as a

    container. Teachers are assigned to

    specific courses.

    A-Part-of Relationship Patterns

    C ll ti M b

  • 8/12/2019 OOAD, Classes, Objects

    126/147

    Collection-Member

    A soccer team is a collection of players.

    Football Team

    Player

    Class Responsibility:

    Id tif i Att ib t d

  • 8/12/2019 OOAD, Classes, Objects

    127/147

    Identifying Attributes and

    Methods Identifying attributes and methods, like

    finding classes, is a difficult activity.

    The use cases and other UML diagrams

    will be our guide for identifying attributes,

    methods, and relationships among

    classes.

    Identifying Class Responsibility

  • 8/12/2019 OOAD, Classes, Objects

    128/147

    Identifying Class Responsibility

    by Analyzing Use Cases andOther UML Diagrams

    Attributes can be identified by

    analyzing the use cases,sequence/collaboration, activity, and

    state diagrams.

  • 8/12/2019 OOAD, Classes, Objects

    129/147

    Assign Each Responsibility To

  • 8/12/2019 OOAD, Classes, Objects

    130/147

    Assign Each Responsibility To

    A Class Assign each responsibility to the classthat it logically belongs to.

    This also aids us in determining the

    purpose and the role that each classplays in the application.

  • 8/12/2019 OOAD, Classes, Objects

    131/147

    Guidelines For Identifying

    Attributes Of Classes

  • 8/12/2019 OOAD, Classes, Objects

    132/147

    Attributes Of Classes

    Attributes usually correspond to nounsfollowed by possessive phrases such as

    cost ofthe soup.

    Guidelines For Identifying

    Attributes Of Classes (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    133/147

    Attributes Of Classes (Con t)

    Keep the class simple; only state enoughattributes to define the object state.

    Guidelines For Identifying

    Attributes Of Classes (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    134/147

    Attributes Of Classes (Con t)

    Attributes are less likely to be fully

    described in the problem statement.

    You must draw on your

    knowledge of the application

    domain and the real

    world to find them.

  • 8/12/2019 OOAD, Classes, Objects

    135/147

    Guidelines For Identifying

    Attributes Of Classes (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    136/147

    Attributes Of Classes (Con t)

    Do not carry discovery of attributes toexcess.

    You can always add more attributes in the

    subsequent iterations.

    Object Responsibility: Methods

    & Messages

  • 8/12/2019 OOAD, Classes, Objects

    137/147

    & Messages

    Methods and messages are the workhorses of object-oriented systems.

    In O-O environment, every

    piece of data, or object,

    is surrounded by a rich set

    of routines called methods.

    Identifying Methods by

    Anal ing UML Diagrams and

  • 8/12/2019 OOAD, Classes, Objects

    138/147

    Analyzing UML Diagrams and

    Use Cases

    Sequence diagrams can assist us in

    defining the services the objects mustprovide.

    Identifying Methods (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    139/147

    C h e c k in g A c c o u n tB a n k C l ie n t

    A T M

    M a c h i n eA cc o u n t

    W it h d r a w C h e c k in g A c c o u n t

    W i t h d r a w S u c c e s s f u l

    R e q u e s t K in d

    E n t e r K i n d

    R e q u e s t A m o u n t

    E n t e r A m o u n t

    P r o c e s s T r a n s a c t io n

    T r a n s a c t i o n s u c c e e d

    D is p e n s e C a s h

    R e q u e s t T a k e C a s h

    T a k e C a s h

    R e q u e s t C o n t i n u a t i o n

    T e r m i n a t e

    P r i n t R e ce i p t

    Identifying Methods (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    140/147

    Methods usually correspond to queriesabout attributes (and sometimes

    association) of the objects.

    Methods are responsible for managingthe value of attributes such as query,

    updating, reading and writing.

    Identifying Methods (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    141/147

    For example, we need to ask thefollowing questions about soup class:

    What services must a soup class

    provide? And What information (from domain

    knowledge) is soup class responsible

    for storing?

    Identifying Methods (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    142/147

    Let's first take a look at its attributeswhich are:

    name

    preparation,

    price,

    preparation time and

    oven temperature.

  • 8/12/2019 OOAD, Classes, Objects

    143/147

    Identifying Methods (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    144/147

    setName

    getName

    setPreparation

    get Preparation

    setCost

    getCost

    setOvenTemperature

    getOvenTemperature

    setPreparationTime getPreparationTime

    Summary

  • 8/12/2019 OOAD, Classes, Objects

    145/147

    y

    We learned how to identify three typesof object relationships:

    Association

    Super-sub Structure (GeneralizationHierarchy)

    A-part-of Structure

    Summary (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    146/147

    The hierarchical relation allows the sharingof properties or inheritance.

    A reference from one class to another is an

    association. The A-Part-of Structure is a special form of

    association.

    Summary (Cont)

  • 8/12/2019 OOAD, Classes, Objects

    147/147

    Every class is responsible for storingcertain information from domain

    knowledge .

    Every class is responsible for performingoperations necessary upon that

    information.