Lecture No.06                      

01.1.     Class Compatibility
A class is behaviorally compatible with another if it supports all the operations of the other class. Such a class is called subtype. A class can be replaced by its subtype.
Derived class is usually a subtype of the base class. It can handle all the legal messages (operations) of the base class. Therefore, base class can always be replaced by the derived class.

Examples
Child class also includes characteristics of its base class.


All the three derived class are behaviourally compatible with base class.

Wherever the file class is it can be replaced by any of its child classes.

01.2.     Polymorphism
It is also essential component of object oriented modeling (paradigm).
In general, polymorphism refers to existence of different forms of a single entity. For example, both Diamond and Coal are different forms of Carbon.

01.3.     Polymorphism in OO Model

In OO model, polymorphism means that different objects can behave in different ways for the same message (stimulus). Consequently, sender of a message does not need to know exact class of the receiver.
Sender sends message to receiver and appropriate method is called on receiver side.

Example – Polymorphism







Shape class hierarchy shape is base class and there are three child classes line circle , triangle. View send draw method to shape class and draw is called according to the nature of actual object present.

Editor sends message print to file class and print is called based on the actual child object of file class message is same and appropriate execution will be done.

01.4.     Polymorphism – Advantages
Messages can be interpreted in different ways depending upon the receiver class
New classes can be added without changing the existing model

In general, polymorphism is a powerful tool to develop flexible and reusable systems

01.5.     Object-Oriented Modeling an Example

Problem Statement

Develop a graphic editor that can draw different geometric shapes such as line, circle and triangle. User can select, move or rotate a shape. To do so, editor provides user with a menu listing different commands. Individual shapes can be grouped together and can behave as a single shape.

Identify Classes

Extract nouns in the problem statement

Develop a graphic editor that can draw different geometric shapes such as line, circle and triangle. User can select, move or rotate a shape. To do so, editor provides user with a menu listing different commands. Individual shapes can be grouped together and can behave as a single shape.

Eliminate irrelevant classes

Editor – Very broad scope. But it is the name of overall system and we are going to model it so we will not make its object. For example if we are going to model computer we will not make its object but its components however if it is component of some other system then it will behave as an object. So it is marked as irrelevant.
User – Out of system boundary, it is interacting with the system from outside of the system.

Add classes by analyzing requirements

Group (of shapes) – required to behave as a shape so it should behave as an object in our system

“Individual shapes can be grouped together and can behave as a single shape”

View – graphic editor must have a display area to show the shapes. We made this object using domain knowledge.

·         Shape
·         Line
·         Circle
·         Triangle
·         Menu
·         Group
·         View


So we have the following classes,



Finding Associations:

Next step is to find associations between the objects.

Identify Associations


Find relationships between objects,

  1. Extract verbs connecting objects,

“Individual shapes can be grouped together

  • Group consists of lines, circles, triangles
  • Group can also consists of other groups (Composition)

Line, circle and triangle have composition relationship.

  1. Verify access paths

a.       View contains (draws) shapes

·         View contains lines
·         View contains circles
·         View contains triangles
·         View contains groups

So there is Aggregation relationship between shapes and View.

Menu sends message to View

So there is Simple One-Way Association relationship between Menu and View.

Identify Attributes of the identified objects


Extract properties of the object,

  1. From the problem statement
Properties are not mentioned
  1. From the domain knowledge

·         Line
                                                              i.      Color
                                                            ii.      Vertices
                                                          iii.      Length
·         Circle
                                                              i.      Color
                                                            ii.      Vertices
                                                          iii.      Radius
·         Triangle
                                                              i.      Color
                                                            ii.      Vertices
                                                          iii.      Angle
·         Shape
                                                              i.      Color
                                                            ii.      Vertices
·         Group
                                                              i.      noOfObjects
·         View
                                                              i.      noOfObjects
                                                            ii.      selected
·         Menu
                                                              i.      Name
                                                            ii.      isOpen

 

Object Model – Graphic Editor

Object model so far is shown below,

Identify Operations


Extract verbs connected with an object

Develop a graphic editor that can draw different geometric shapes such as line, circle and triangle. User can select, move or rotate a shape. To do so, editor provides user with a menu listing different commands. Individual shapes can be grouped together and can behave as a single shape.

Eliminate irrelevant operations
Develop – out of system boundary
Behave – have broad semantics

Following are selected operations:
          Line
        Draw
        Select
        Move
        Rotate
          Circle
        Draw
        Select
        Move
        Rotate
          Triangle
        Draw
        Select
        Move
        Rotate
          Shape
        Draw
        Select
        Move
        Rotate
          Group
        Draw
        Select
        Move
        Rotate
          Menu
        Open
        Select
        Move
        Rotate
Extract operations using domain knowledge

          View
        Add
        Remove
        Group
        Show
        Select
        Move
        Rotate

 

Object Model after adding operations 

Identify Inheritance


  1. Search lines like “is a kind of” by looking at keywords like “such as”, “for example”, etc
                            
“…shapes such as line, circle and triangle…”
        

By analyzing requirements

“Individual shapes can be grouped together and can behave as a single shape”

Refining the Object Model


Application of inheritance demands an iteration over the whole object model
In the inheritance hierarchy,
·         All attributes are shared
·         All associations are shared
·         Some operations are shared
·         Others are overridden

Refining the Object Model


·         Share associations
o   View contains all kind of shapes
o   Group consists of all kind of shapes
·         Share attributes
o   Shape – Line, Circle, Triangle and Group
§  Color, vertices
·         Share operations
o   Shape – Line, Circle, Triangle and Group
§  Select
§  Move
§  Rotate
·         Share the interface and override implementation

o   Shape – Line, Circle, Triangle and Group
§  Draw

Post a Comment

Don't Forget To Join My FB Group VU Vicky
THANK YOU :)

Previous Post Next Post