01. object web - ooad i

Upload: rohitnhr

Post on 10-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 01. Object Web - OOAD I

    1/61

    Object Oriented Programming

    Object WebBapayya Choudhary Maganti

    2-2-647/182/J, C. E. Colony, New Nallakunta, Hyderabad

    - 500 013.- - -

  • 8/8/2019 01. Object Web - OOAD I

    2/61

    Course Contents

    Object Oriented BackgroundObject Oriented Programming Concepts

    Analysis

    Use Case Modeling

    DesignObject Modeling

    CRCClass Diagrams

    Dynamic ModelingSequence Diagram

    Collaboration DiagramState Diagrams

    Activity Diagrams

    Component Diagram

    Deployment DiagramCase Stud Drawin Editor Problem

  • 8/8/2019 01. Object Web - OOAD I

    3/61

    Background

    Object WebBapayya Choudhary Maganti

    2-2-647/182/J, C. E. Colony, New Nallakunta, Hyderabad

    - 500 013.- - -

  • 8/8/2019 01. Object Web - OOAD I

    4/61

    What Is Object Orientation?

    Term Object-Orientation means.The organization of software as a collection of discrete

    objects that incorporate both data structure and behavior.

    A new technology based on objects and classes.Use of objects and classes in analysis.

    Everything here is object and process is sending a

    message to objects.

    A language is object oriented if supports the following

    four proprieties:

    Abstraction.

    Polymorphism.

    Encapsulation.

    Inheritance.

  • 8/8/2019 01. Object Web - OOAD I

    5/61

    Object-based Vs Object-oriented

    Object-based programming usually refers toobjects without inheritance and hence without

    polymorphism.

    These languages support abstract data types

    and not classes, which provide inheritance and

    polymorphism.Object-oriented programming refers to the

    objects with inheritance and polymorphism.

  • 8/8/2019 01. Object Web - OOAD I

    6/61

    What Is the Background?

    Arrived from Process.

    Talk about the Behavior Centric not Data Centric.

    Simula 67 the first Object Oriented Language, 1967.

    Objects, Classes, Inheritance, Dynamic Typing.

    Smalltalk first Pure Object Oriented Language, 1969.

    Classes, Objects, Inheritance.Dynamic Typing.

    First Graphics Environment.

    First Use of Mouse in Programming Environment.

    Introduced first Multi Threaded Environment.

    Form Parc of Xerox Corporation.

    For more info look at parc.xerox.com.

  • 8/8/2019 01. Object Web - OOAD I

    7/61

    OO Programming Languages

    Statically-typed:Memory allocation at compile time

    No Runtime Class, Objects

    Type Defined.

    Example: C++

    Dynamically-typed:

    Memory Allocation at Run-time

    Runtime Classes, Object

    Runtime Inheritance

    No Data types

    Example: Smalltalk

    Both:

    Example: Java

  • 8/8/2019 01. Object Web - OOAD I

    8/61

    Statically-Typed:

    C++

    Classic-Ada

    Dragoon

    Emerald/Jade

    Object Pascal

    Trellis/Owl

  • 8/8/2019 01. Object Web - OOAD I

    9/61

    Dynamically-Typed:

    Actors Language

    C+@

    Flavors

    Python

    Self

    Smalltalk

  • 8/8/2019 01. Object Web - OOAD I

    10/61

    Both:

    Actor

    Ada95

    BETA

    C++ (With RTTI)

    Cecil

    CLOS

    Eiffel

    Java

    Modula-3

    Objective-C

    Sather

  • 8/8/2019 01. Object Web - OOAD I

    11/61

    Object-Oriented Operating Systems

    Object-Oriented Operating Systems provideresources through objects, sometimes all the

    way down to to the machine.

    These are almost always distributed systems

    (DOS or DPOS), allowing objects to be passed

    freely between machines.

  • 8/8/2019 01. Object Web - OOAD I

    12/61

    Object-Oriented Operating Systems

    Some of the Object-Oriented OperatingSystems:

    Apertos.

    Chorus Micro-kernel.

    Choices.

    GEOS.Mach.

    NachOS.

    Ouverture Project.

    Peace.

    Spring.

  • 8/8/2019 01. Object Web - OOAD I

    13/61

    Object-Oriented Databases

    Object-oriented databases are databases thatsupport objects and classes.

    They are different from the more traditionalrelational databases because they allow

    structured sub objects, each object has its own

    identity, or object-id and because of support formethods and inheritance.

  • 8/8/2019 01. Object Web - OOAD I

    14/61

    Object-oriented Databases

    It is also possible to provide relationaloperations on an object-oriented database.

    OODBs allow all the benefits of object-orientation, as well as the ability to have a

    strong equivalence with object-oriented

    programs, an equivalence that would be lost ifan alternative were chosen, as with a purely

    relational database.

  • 8/8/2019 01. Object Web - OOAD I

    15/61

    List of Object-oriented Databases:

    Research Systems AVANCE

    CLOSQL

    ConceptBase*

    COOL/COCOON

    Encore*

    Exodus*

    Machiavelli

    MOOD4-PC*

    OBST/STONE*

    Ode*

    Oggetto

    Orion

    OTGen

    PLOB

    VODAK

    Commercial Systems ArtBASE, EasyDB

    GemStone

    ITASCA, Matisse

    NeoAccess

    OBST+

    O2, Objectivity

    ObjectStore

    Ontos

    Odapter/OpenODB program (HP)

    Unisys Universal Repository

    Versant VisualWorks

    OOFILE

    Phyla, POET

    Statice UniSQL

  • 8/8/2019 01. Object Web - OOAD I

    16/61

    Object-oriented Methodologies

    List of Methodologies:Bernard

    BON

    BoochCoad/Yourdon

    Colbert

    de ChampeauxEmbley

    EVB

    Rebecca WirfsFUSION

    HOOD

    IBM

    Jacobson

    Martin/OdellOoram

    Room

    RumbaughShlaer and Mellor

    Open

    UMLWasserman

    Wirfs-Brock

  • 8/8/2019 01. Object Web - OOAD I

    17/61

    UML

    Collection of concepts from variousmethodologies.

    From:BOOCH.

    RUMBAUGH.

    JACOBSON.

    Started in 1995.

    Adapted by OMG.

    Current Version 1.3.

    Can be adapted for any application.

  • 8/8/2019 01. Object Web - OOAD I

    18/61

    UML, Stepping ahead

    Unified Method 0.8

    Start 1/95, OOPSLA 10/95

    Booch OMT

    UML 0.9, 0.916/96, 9/96

    OOSE Others

    UML 1.0OMG Submission 1/97

    UML Partners Expertise

    UML 1.1

    OMG Revision 9/97Adoption 11/97

    Others

    UML 1.3RTF report 4/99

    OMG Feedback

    UML 1.?Expected Shortly

    OMG/RTF Revisions

  • 8/8/2019 01. Object Web - OOAD I

    19/61

    Object Oriented Programming

    Concepts - Fundamentals

    Object WebBapayya Choudhary Maganti

    2-2-647/185, C. E. Colony, New Nallakunta, Hyderabad - 500 013.

    Phone: +9140-7422414, E-mail: [email protected], Web: www.objweb.com

  • 8/8/2019 01. Object Web - OOAD I

    20/61

    What is an Object?

    The entity which represents somethingObjects is having a concrete physical form as

    well as intelligence, because we not onlyperceive them but also make them do

    something.

    Physical ObjectAn object may be invisible to the human eye

    but having some basic form of intelligence.

    Conceptual Object

  • 8/8/2019 01. Object Web - OOAD I

    21/61

    SBI/K

    Object have State, Behavior, Identity andKnowledge about Other Objects

    State is attributes

    Behavior is methods

    Identity is uniqness

    Knowledge is message sent between to objects.

    State

    BehaviourIdentity

    x=50, y=50

    isFirstQuadrantPoint ( )Point Object at memory AF00Knowledge

  • 8/8/2019 01. Object Web - OOAD I

    22/61

    Identity

    Each Object is different form other.All Objects Have Identity.

    Identity is that property of an object thatdistinguishes it from all other objects. (Booch).

    An object is a reality and it is an entity which

    exists in time and space. We are able toidentify it as an object because of its

    IDENTITY. This is true for all objects in the real

    world.

    We see a lion as a lion and not a horse

    because of its identity.

  • 8/8/2019 01. Object Web - OOAD I

    23/61

    Identity

    If we look at any two similar object, thepossible outer look may be same but there may

    be lot of difference between them.

    My be two pens are appearing same, but the

    are different.

    Similarly, two identical twins are nothing buttwo distinct objects.

  • 8/8/2019 01. Object Web - OOAD I

    24/61

    Objects Know Each Other

    Objects can't behave independentlyLike humans objects need to know about other

    objects in the system.

    All objects are intelligent

    We give them levels of intelligence we would

    normally associate with humans.Objects are not in isolation

    We share the world around us with other objects.

  • 8/8/2019 01. Object Web - OOAD I

    25/61

    Objects Communicate With Each Other.

    Objects live in a dynamic world where theyexchange information and communicate with anumber of objects getting certain things done.

    When a object receives the messages and ifthe object cannot understand the informationthen it searches for the object which can

    understand this and send this message to theother object.

    There are two types of communicationsbetween objects.The direct communication.

    The indirect communication.

  • 8/8/2019 01. Object Web - OOAD I

    26/61

    Behavior

    By communication an operation was achieved.The operation placed a certain

    RESPONSIBILITY.

    A property is gives uniqueness to Object.

    The term property denotes attributes.

    Both property and attribute may be used

    interchangeably.

    Properties are usually static, which means thatthey do not change over a period of time.

  • 8/8/2019 01. Object Web - OOAD I

    27/61

    Behavior

    Attributes have values.An attribute is a data value held by the objects

    in a grouping of similar objects.

    It is important to note here that ATTRIBUTE

    SHOULD BE A PURE DATA VALUE NOT AN

    OBJECT. (Not valid for pure object orientedprogramming languages.)

    Unlike objects, data values have no identity.

  • 8/8/2019 01. Object Web - OOAD I

    28/61

    State

    Preceding each of these state - change is a stimulus(Booch) or event (Rumbaugh) or action (Booch).

    Therefore, the current state of any object depends on:

    Preceding State.

    Object's inherent properties (or attributes).

    Stimulus received by the object. Which may cause the

    properties to undergo changesCurrent Status =

    Inherent Properties +

    Preceding State +

    Stimulus received +

    Argument Passed with Stimulus.

  • 8/8/2019 01. Object Web - OOAD I

    29/61

    State

    The State of an object may be defined as:The state of an object at any given instance is determined

    by the combination of its precedent status, its internalproperties, the current values of these properties and the

    stimulus it receives.The fact that every object has a state implies that every

    object takes up some amount of space (either in thephysical world or in computer memory).

    Now we can define Behavior of an object as:Behavior is how an object acts or reacts in terms of its state

    changes and message passing.

    Colloquially the word object is also used to indicate agroup of similar objects.Instance Object -> Instance.

    Class Object -> Class.

  • 8/8/2019 01. Object Web - OOAD I

    30/61

    Important Aspects

    An object with the same name may occur incompletely different domains.

    Ex: Customer.

    An object is characterized by what it is used for

    and by the information that is attached to it.

    i.e., attributes.Use of an object is captured by its behavior.

    i.e., by the operation that it can offer to other object

    in its environment.

    C S f O

  • 8/8/2019 01. Object Web - OOAD I

    31/61

    Client Server Nature of Objects

    An object uses another object for performingan operation by sending a stimulus.

    Each stimulus has an unique name that clearly

    determines the operation to be performed.

    The requirements placed on the server object may

    have several responsibilities depending upon its

    use.

    Client Object Server Object

    Cli t S N t f Obj t

  • 8/8/2019 01. Object Web - OOAD I

    32/61

    Client Server Nature of Objects

    When a client objects sends a stimuli to a server object, theonly information that is available to the client object is the

    type of operation that can be performed by the server

    object.

    The client knows only the name of the operation to be

    performed by the server which is sent as the stimuli along

    with various types of information each operation needs in

    order to perform the task.The names and types of information are called the

    operations 'signature'.

    Remember an object can perform different operations

    depending upon usage, and, therefore will have different

    'signatures'.

    The combination of all such signatures of an object is called

    the objects protocol.

    Obj t D i ti

  • 8/8/2019 01. Object Web - OOAD I

    33/61

    Object Description

    An object can be described in two different, butrelated ways.

    The external description, which shows how

    others can use the object and the responsibilitiesthe objects has towards others. This description

    contains only the objects protocol (how it can be

    used). This is also sometimes called the objectsspecification.

    The internal description specifies the objects

    various attributes and how each operation isrealized. This description is called the objects

    implementation.

    A di t B h

  • 8/8/2019 01. Object Web - OOAD I

    34/61

    According to Booch

    Without this conception framework, you maybe programming in a language such asSmalltalk, object Pascal, C++, CLOS, Eiffel,

    Ada, but your design is going to smell like aFORTRAN, Pascal or C application.

    You will have missed out on or otherwise

    abused the expressive power of the object-oriented language you are using forimplementation.

    More importantly, you are not likely to havemastered the complexity of the problem athand.

    R l t d C t

  • 8/8/2019 01. Object Web - OOAD I

    35/61

    Related Concepts:

    Important concepts & Related Topics:Abstraction.

    Encapsulation.

    Generalization.Concurrence.

    Persistence.

    Polymorphism.

    Composition.

    Factorization.

    Delegation.

    Refinement.

    Multi-layer Architecture.

  • 8/8/2019 01. Object Web - OOAD I

    36/61

    Abstraction

    View of the ObjectObject Web, Bapayya Choudhary Maganti

    Abstraction

  • 8/8/2019 01. Object Web - OOAD I

    37/61

    Abstraction

    One of the two ways humans cope withcomplex problems to spot

    Similarities between objects, processes, situations.

    Break down large problems into manageable level.

    A viewer abstracts objects in relation to the problem

    perspective.

    Let us consider an example of how 'human beings' may

    be viewed in different domains.

    Domain Viewer Abstraction

    Biology Biologist SpeciesPolitics Politician Vote Bank

    Industries Manager Resource

    Food habits Man-eater Food

    Abstraction

  • 8/8/2019 01. Object Web - OOAD I

    38/61

    Abstraction

    Abstraction is a phenomenonBy which a viewer is able to identify unique

    features or characteristics of an object which

    separate the object from all other objects in a givenproblem domain.

    There are four metrics to ensure the design of

    class hierarchy and relations are:

    Coupling

    CohesionSufficiency

    Completeness

  • 8/8/2019 01. Object Web - OOAD I

    39/61

    Cohesion

  • 8/8/2019 01. Object Web - OOAD I

    40/61

    Cohesion

    Cohesion measures the extent of connectivityamong the elements of a single object or class.

    The most desirable form of cohesion is the

    FUNCTIONAL COHESION.i.e. We check if elements comprising an abstraction

    are truly representative of the behaviors.

    You can't abstract an animal and a vehicle ifthey don't serve the same semantic purpose.Both animal and vehicle may be abstracted in the

    class LoadCarrier but cannot be abstractedtogether if we are looking at a race horse and apassenger car.

    Sufficiency

  • 8/8/2019 01. Object Web - OOAD I

    41/61

    Sufficiency

    This means that the class captures in itsabstraction all the expected behavior of the

    class for meaningful interaction.

    For example

    if we are designing a class 'UpdateItem', it makes

    sense to include an operation that will add an itemor remove an item or modify an item.

    Though this may sound very routine, it has been

    noticed that many times we neglect or miss out toinclude all the operations.

    Completeness

  • 8/8/2019 01. Object Web - OOAD I

    42/61

    Completeness

    This has two formsExtension of sufficiency

    A complete class or module is one whose interface is

    general enough to be commonly usable to any client.In other words the interface should be such that it covers

    all aspects of the abstraction.

    Extension of generalizationThe class should have implemented all the expected

    abstract or virtual functions of the super class.

    The class hierarchy is considered to complete when allthe sub classes are defined and the sub-classes are

    defined as per the minimum expectations of the super

    class.

    The Process of Abstraction

  • 8/8/2019 01. Object Web - OOAD I

    43/61

    The Process of Abstraction

    Booch saysClasses and objects should be at the right level of

    abstraction;

    Neither too high nor too low.

    The process of abstraction, is incremental anditerative.We study the problem domain

    Identify objects which may seem disparate in the beginning Identify their relationship and group them in different classes

    based on their common characteristics.

    The identification of abstractions involvesKnowledge of the problem domain

    Discovery

    Invention.

  • 8/8/2019 01. Object Web - OOAD I

    44/61

    Encapsulation

    Hide for right Abstraction & CouplingObject Web, Bapayya Choudhary Maganti

    Encapsulation

  • 8/8/2019 01. Object Web - OOAD I

    45/61

    Encapsulation

    Encapsulation actually means to capsulate.A capsule means something held in a covering.

    What is inside can not be seen.Enclose something or Encapsulate something

    inside the object.

    Public

    PrivateProtected

    ... Encapsulation

  • 8/8/2019 01. Object Web - OOAD I

    46/61

    ... Encapsulation

    Abstraction takes care of what an object cando i.e., the various operations it can perform

    Encapsulation takes care of how it does it i.e.,

    the attributes and the implementation details.

    All objects have two parts

    The abstracted visible part - INTERFACEThe encapsulated hidden - IMPLEMENTATION

    What Is Achieved by Encapsulation?

  • 8/8/2019 01. Object Web - OOAD I

    47/61

    What Is Achieved by Encapsulation?

    Encapsulation is the process of hiding therepresentation of an abstraction that make up

    the structure of a class of objects and their

    behavior.

    If the implementation is modified we continue

    to use the object without any modifications tothe interface.

    According to Booch.

    Intelligent encapsulation localizes design decisionsthat are likely to change.

    Refactoring

  • 8/8/2019 01. Object Web - OOAD I

    48/61

    Refactoring

    In Refactoring is the process of changing theobject without changing the Interface.

    Interface is public method defined in Class

    Note:

    If an Object need implementation to be modified

    without changing the interface it is terms adRefactoring.

    This may not be possible always.

    Refactoring minimizes the changes on other object.This process ensures that the classes have right

    level of coupling and will have minimum/no impact

    on the collaborating classes.

    Achieving Encapsulation

  • 8/8/2019 01. Object Web - OOAD I

    49/61

    Achieving Encapsulation

    Smalltalk.By default all attributes are private and methods are public.

    It is only documentation process to achieve private

    methods.Java.

    Variables and methods can be declared as private public

    and protected.Can have package level access modifiers and can mark

    classes as private to package.

    Can define inner classes, which have class scope.

    C++.

    Variables and methods can be declared as private, public

    and protected.

    Can have private, protected, public inheritance.

    Why Public, Protected and Private

  • 8/8/2019 01. Object Web - OOAD I

    50/61

    Why Public, Protected and Private

    Attributes of classMake sure that all attributes are declared as private

    and give protected or public access modifiers (get

    and set methods)

    Methods of class

    Make sure that all methods are declared as

    protected (never private) and only those required

    as public.

    Different levels of EncapsulationCollaboration level

    Inheritance level

    Package level

    Level of Encapsulation

  • 8/8/2019 01. Object Web - OOAD I

    51/61

    p

    Collaboration levelBetween two classes there exists public and private

    methods where the collaborating class can access

    only the public behavior of other class but not theprivate behavior.

    Inheritance level

    Sub class is extension to the existing behavior ofthe super class and it should be able to access allthe behavior of the super class.

    Package levelClasses can be defined as public or private to

    package and this should minimize the couplingbetween the packages.

  • 8/8/2019 01. Object Web - OOAD I

    52/61

    Inheritance

    Specialization & GeneralizationObject Web, Bapayya Choudhary Maganti

    Generalization and Inheritance.

  • 8/8/2019 01. Object Web - OOAD I

    53/61

    Generalization and Specialization areimportant aspects of Object Orientation which

    give rise to the concepts of HIERARCHY and

    INHERITANCE.

    Each individual object in a class is called an

    INSTANCE of its class.The terms 'instance' and 'object' are

    interchangeable (for C++)

    Car Van

    FourWheeler

    ... Generalization

  • 8/8/2019 01. Object Web - OOAD I

    54/61

    An instance of a subclass is simultaneously aninstance of all its ancestor classes.

    Each subclass not only inherits all the features

    of its superior class, but adds its own specific

    attributes and operations as well. It may

    augment or restrict the existing structure andbehavior of a super-class.

    Classes are related to one another via

    inheritance relationships.

    ... Generalization

  • 8/8/2019 01. Object Web - OOAD I

    55/61

    The most specialized class in a hierarchy isknown as the leaf class.

    The most generalized class is known as the

    base class.

    The leaf classes are also known as concrete

    classes.Only the leaf class (or concrete class) will have

    instances.

    The base class and other intermediary classes

    usually do not have any instances.

    ... Generalization

  • 8/8/2019 01. Object Web - OOAD I

    56/61

    Abstract classes are not expected to haveinstances of their own.

    Abstract classes are written with the

    expectation that its subclasses will add to itsstructure the behavior which implements

    methods.Single inheritance means each subclass has

    exactly one super-class.

    Multiple inheritance means each such classhas more than one super-class.

    ... Generalization

  • 8/8/2019 01. Object Web - OOAD I

    57/61

    The terms Generalization, Inheritance andSpecialization refer to the same underlying

    idea, and are many a time used

    interchangeably.Generalization is used while modeling and

    implementation. It facilitates modeling bystructuring classes and capturing what is

    similar and what is different amongst classes.

    Identify the behavior of different classes

  • 8/8/2019 01. Object Web - OOAD I

    58/61

    ShortInteger

    Integer Float

    Number

    LongInteger

    Magnitude

    CharacterPoint

    Solution

  • 8/8/2019 01. Object Web - OOAD I

    59/61

    ShortInteger

    Integer Float

    Number

    LongInteger

    Magnitude

    CharacterPoint

    Abstract Methods: +, -, , =, !=

    Concrete Methods: +, -,

  • 8/8/2019 01. Object Web - OOAD I

    60/61

    Build the hierarchy/classes for the following.

    Identify all classes in a coordinate system.

    Identify the major responsibilities of the classes.

    For a drawing editor problem define the elements.Rectangle.

    Has start point, stop point, the diagnoll opposite corners

    Line.Has start point, stop point.

    Circle.

    Has center and radius.

    Ellipse.

    Has center, major radius, minor radius.

    Solution

  • 8/8/2019 01. Object Web - OOAD I

    61/61

    ShapeLine

    Rectangle

    Ellipse

    Point

    Shape

    Line Rectangle Ellipse

    Point