Page 14 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 14

Object Oriented Analysis and Design




                    Notes          but inherit-mice and polymorphism add power. The ability to abstract is probably the most
                                   important skill required for object oriented development.

                                   1.3.2  Encapsulation

                                   Encapsulation is the process of encapsulating the elements of an abstraction that constitutes its
                                   structure and behavior; encapsulation serves to separate the contractual interface of an abstraction
                                   and its implementation.
                                   It can also be called as information hiding. It consists of separating the external aspects of an
                                   object, which are accessible to other objects, from the internal implementation details of the
                                   object, which are hidden from other objects. It is not unique to object oriented languages.
                                   Encapsulation (also information hiding) consists of separating the external aspects of an object,
                                   which are accessible to other objects, from the internal details of the object, which are hidden
                                   from other objects.
                                   Objects have an outside (how they are seen or interact) and an inside (what they are.)
                                   Encapsulation means that every object is self-contained.

                                   Encapsulation is not a unique concept to OO languages, but the ability to combine data and
                                   behavior in an object provides cleaner encapsulations than with conventional languages.
                                   Objects restrict the visibility of their resources (attributes and methods) to other users. Every
                                   object has an interface, which determines how other objects can interact with it. The
                                   implementation of the object is encapsulated, that is, invisible outside the object itself.
                                   Separate the external aspects of an object (its interface) from the internal implementation details
                                   (implementation).
                                   Proper encapsulation keeps objects from becoming interdependent (or coupled) - internal details
                                   can change with no affect on the user. Encapsulation places a premium on interfaces.

                                       !
                                     Caution Encapsulated details can change with no impact to a client, while an interface
                                     change directly affects a client.

                                   1.3.3  Combining Data and Behaviour

                                   The caller of an operation need not consider how many implementations of a given operation
                                   exist. Operator polymorphism shifts the burden of deciding what implementation to use from
                                   the calling code to the class hierarchy.
                                   As an example, let us talk about an object oriented program calling a draw procedure for
                                   drawing different figures say a polygon, circle, or text. The decision of which procedure to use
                                   is made by each object, based on its class.

                                   1.3.4  Sharing

                                   Inheritance of both data structure and behavior allows common structure to be shared among
                                   several similar subclasses without redundancy. The sharing of code using inheritance is one of
                                   the main advantages of object oriented languages.
                                   One of the reasons for the popularity of object-oriented techniques is that they encourage sharing
                                   at different levels. Inheritance of both data structure and behavior allows common structure
                                   (base class) to be used in designing many subclasses based on basic characteristics of base class,



          8                                 LOVELY PROFESSIONAL UNIVERSITY
   9   10   11   12   13   14   15   16   17   18   19