object oriented technic notes(unit3)

Upload: amir-khan

Post on 04-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    1/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    1

    ECSECSECSECS----503: Object Oriented Techniques503: Object Oriented Techniques503: Object Oriented Techniques503: Object Oriented Techniques

    UnitUnitUnitUnit ---- IIIIIIIIIIII

    Object Oriented AnalysisObject Oriented AnalysisObject Oriented AnalysisObject Oriented Analysis and Designand Designand Designand Design::::

    Object oriented analysis and design is the software engineering approach that models asystem as group of interacting objects. Each object represents some entity that has

    properties and behaviors.

    Object Oriented Analysis (OOA) applies to analysis the functional requirement fora system. Object design the analysis model to produce implementation

    specification.

    In analysis phase we focus on what the system does and in design phase we focuson how the system does it.

    Object Oriented Analysis (OOA) is concerned with developing an object orientedmodel of an application. The identified objects reflect entities and operations that

    are associated with the problem to be solved.

    Object Oriented Design (OOD) process involves designing the object-classes andthe relationship between these classes. When the design is released as an

    executing program, the required objects are created dynamically using class

    definition.

    The purpose of AnaThe purpose of AnaThe purpose of AnaThe purpose of Analysis and Design are to:lysis and Design are to:lysis and Design are to:lysis and Design are to:o Transform the requirements into system design.o Represent a robust architecture for the system.o The result of Analysis and Design is a Design ModelDesign ModelDesign ModelDesign Model that serve as an

    abstraction of the source code, i.e. the Design Model acts as a blueprint of

    how the source code is structured and written.

    o The Design Model consists of design classes structured into designpackage, it also contains description of how objects of these classes

    collaborate to perform use cases.

    o The design activities are centered around the notion of architecture.o Architecture is represented by a number of architectural views that

    capture the major structural design decisions.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    2/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    2

    o The architecture is an important vehicle not only for developing goodDesign Model but also for increasing the quality of any model built during

    system development.

    Difference between Analysis & DesignDifference between Analysis & DesignDifference between Analysis & DesignDifference between Analysis & Design ::::

    Benefits Of Object Oriented Analysis (OOA)Benefits Of Object Oriented Analysis (OOA)Benefits Of Object Oriented Analysis (OOA)Benefits Of Object Oriented Analysis (OOA) ::::o Easy mapping to the real world and easily verified by the customer.o Easy to understand the analysis model.o The analysis phase is independent of any programming language.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    3/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    3

    Object Design:Object Design:Object Design:Object Design:

    Object Oriented Design (OOD) is a process that focuses on physical implementation of

    the system. Object Oriented Design (OOD) is concerned with developing Object Oriented

    Model (OOM) of a software system to implement the requirement which is identified

    during Object Oriented Analysis (OOA).

    Designs can be developed using objects that have been created in previous design. This reduces design, programming and validation costs. It may also lead to the use of

    standard objects and reduces the risks involved in software development.

    The term object and object-oriented are now widely used. They are applied to different type of entity, design methods, systems and

    programming language. An object is an entity that has a state and a defined set of operations which operate on

    that state.

    The state is represented as a set of object attributes. The operations associated with the object provide services to other objects which

    request these services when some computation is required.

    Objects are created according to an object class definition. An object class definition serves as a template for creating objects. It includes

    declarations of all the attributes and operations which should be associated with an

    object if that class.

    The six basic concepts of Object Oriented Design (OOD) are:

    o Objects.o Classes.o Encapsulation / Information Hiding.o Abstraction and Interface.o Inheritance.o Polymorphism.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    4/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    4

    Combining The Three Models:Combining The Three Models:Combining The Three Models:Combining The Three Models:

    After analysis we have object, dynamic and functional model, but the object model is the

    main framework around which the design is constructed. A software combines all the

    three models i.e. it uses data structure (Object Model), its sequence the operation in time

    (Dynamic Model) and it passes the data and control among object ( Functional Model).

    ObjectObjectObjectObject Model :Model :Model :Model :

    o It describes the structure of objects in a system.o It shows the attribute, operations and relationship to other objects.o It provide context for the state and interaction model.o Object are the units into which we divide the system.o Classes are arranged into hierarchies, and associated with other classes.o Class defines the attributes and operations carried by each object instance.

    DynamicDynamicDynamicDynamic Model :Model :Model :Model :

    o The dynamic model describes those aspect of a system concerned with time andsequencing of operations.

    o The dynamic model is represented graphically with state diagramsstate diagramsstate diagramsstate diagrams.o In state model, we have events that describes some changes and states that is

    defined for events.

    o State diagram express the state model, each state diagram show the different statesand events that occur in a system.

    FunctionalFunctionalFunctionalFunctional Model :Model :Model :Model :

    o It describes interaction between the objects, how the objects collaborate to achievebehavior of the system.

    o Use-case, sequence and activity diagram describe the interactional model.o Use-case shows the interaction between system and actor.o Sequence diagram shows the objects that interact and also show the time sequence

    of their interaction.

    o Activity diagram shows the flow of control.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    5/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    5

    Development Steps in OOT:Development Steps in OOT:Development Steps in OOT:Development Steps in OOT:The following activities are done for developing a system:

    1) Develop a problem statement.2) Make an object/class model.

    a. Identify the object and classes.b. Develop a data dictionary for classes attributes and operations.c. Add association between classes.d. Group the classes into modules.

    3) Make a state/dynamic model.a. Prepare a scenario.b. Indentify events between the objects and prepare an event trace for

    each scenario.

    c. Develop a state diagram.4) Make an interaction/functional model.

    a. Use data flow diagram, sequence diagram, use-case diagram andactivity diagram.

    b. Describe what each function does.5) Verify, iterate and refine the models.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    6/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    6

    Designing Algorithm:Designing Algorithm:Designing Algorithm:Designing Algorithm:

    Each operation specified in the functional model must be formulated as an algorithm.

    The steps involve in designing algorithm, designer must:

    1)Choosing Algorithm:Choosing Algorithm:Choosing Algorithm:Choosing Algorithm:It is very important to select the right algorithm. While choosing an algorithm following

    point should be considered:

    a)Computational Complexity:- For analyzing an algorithm, we determine the amount ofresources (time and space) necessary to execute it efficiently.

    b)Ease Of Implementation & Understandability:- The algorithm should be easilyunderstandable and can be easily implemented because to implement difficult algorithm

    need more man power and resources which increase the overall cost of project.

    c)Flexibility:- The client requests keeps on changing, it is very important that the algorithmshould be adaptable to those changes.

    2)Choosing Data Structure:Choosing Data Structure:Choosing Data Structure:Choosing Data Structure:Choosing algorithm involves choosing the data structure they work on. During object

    design we must choose the form of the data structure that will permit efficient

    algorithms. Data structure play very important role in the success and failure of an

    algorithm.

    3)Defining Internal ClassesDefining Internal ClassesDefining Internal ClassesDefining Internal Classes & Operation:& Operation:& Operation:& Operation:During the expansion of algorithms, new classes of objects may be needed to hold

    intermediate results. New, low-level operations may be invented during the

    decomposition of high-level operation.

    4)Assigning Responsibility To Classes:Assigning Responsibility To Classes:Assigning Responsibility To Classes:Assigning Responsibility To Classes:Many operations have obvious target objects, but some operations can be performed at

    several places in an algorithm by several objects. Assigning responsibility for such

    operations can be frustrating. When a class is meaningful in the real world, then the

    operations on it are usually clear. When we have more than one objects in a system, we

    must decide which object plays the lead role in the system.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    7/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    7

    Design Optimization:Design Optimization:Design Optimization:Design Optimization:

    The basic design model uses the analysis model as the framework for

    implementation. During design optimization, the designer must:

    1) Adding Redundant Associations For Efficient Access:Adding Redundant Associations For Efficient Access:Adding Redundant Associations For Efficient Access:Adding Redundant Associations For Efficient Access:During analysis, it is undesirable to have redundancy in the association

    network because redundant association does not add any information.

    During design, however, we evaluate the structure of the object model for an

    implementation. The association that was useful during analysis may not form

    the most efficient network then network should be restructured by adding

    new associations.

    2) Rearranging Execution Order For EfficRearranging Execution Order For EfficRearranging Execution Order For EfficRearranging Execution Order For Efficiency:iency:iency:iency:After adjusting the structure of the object model to optimize frequent

    traversals, the next thing to optimize is the algorithm itself. Actually, data

    structure and algorithm are directly related to each other, but we find that

    usually the data structure should be considered first.

    3) Saving Derived Attributes To Avoid ReSaving Derived Attributes To Avoid ReSaving Derived Attributes To Avoid ReSaving Derived Attributes To Avoid Re----compcompcompcomputation:utation:utation:utation:Data that is redundant because it can be derived from other data can be

    cached or stored in its computed from to avoid the overhead of re-

    computing it. New objects or classes may be defined to retain this information.

    The class that contains the cached data must be updated if any of the objects

    that it depends on are changed.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    8/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    8

    Implementation Of Control:Implementation Of Control:Implementation Of Control:Implementation Of Control:

    The designer must refine the strategy for implementing the state-event models present in

    the dynamic model. There are three basic approaches to implementing the dynamic

    model:

    1) State As Location Within A Program:State As Location Within A Program:State As Location Within A Program:State As Location Within A Program:The location of a control within a program implicitly defines the program state.

    One technique of converting a state diagram to code is as follows:

    a) Identify the main control path. Identify a path through the diagram thatcorresponds to the normally expected sequence of events. Write the names of

    states along this path as a linear sequence. This becomes a sequence of statements

    in the program.

    b) Identify alternate paths that branch off the main path and rejoin it later. Thesebecome conditional statement in the program.

    c) Identify backward path that branch off the main loop and rejoin it earlier. Thesebecome loops in the program.

    d) The states and transitions that remain correspond to execution condition. They canbe handled by exception handling supported by the language.

    2) State Machine Engine:State Machine Engine:State Machine Engine:State Machine Engine:This approach allows you to quickly progress from the analysis model to a skeleton

    prototype of the system by defining classes from the object model, state machine from

    the dynamic model, and creating stubstubstubstub of the action routines. A stub is the minimal

    definition of a function or subroutine without any internal code ( Code to return a

    pre-calculated or contrived values may be included).

    3) Control As Concurrent Tasks:Control As Concurrent Tasks:Control As Concurrent Tasks:Control As Concurrent Tasks:An object can be implemented as a task in the programming language. This is the

    most general approach, as it preserves the inherent concurrency of real objects. Events

    are implemented as inter-task calls using the facilities of the language. The task uses

    its location within the program to keep track of its state.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    9/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    9

    Adjustment Of Inheritance:Adjustment Of Inheritance:Adjustment Of Inheritance:Adjustment Of Inheritance:

    As object design progresses, the definition of classes and operations can often be adjusted

    to increase the amount of inheritance. The designer should:

    1) ReReReRe----arranging Classes & Operations:arranging Classes & Operations:arranging Classes & Operations:arranging Classes & Operations:Sometimes the same operation is defined across several classes and can easily be

    inherited from a common ancestor, more often operation in different classes are

    similar but not identical. The following kind of adjustment can be used to increase the

    chance of inheritance:

    a) Some operations may have fewer arguments than other. The missing argumentcan be added but ignored.

    b) Similar attributes in different classes may have different names. Give the attributesthe same name and move them to a common ancestor class.

    c) An operation may be defined on several different classes in a group but beundefined on the other classes. Define it on the common ancestor class and

    declare it as a no-op on the classes that do not care about it.

    2) Abstracting Out Common Behaviour:Abstracting Out Common Behaviour:Abstracting Out Common Behaviour:Abstracting Out Common Behaviour:If a set of operations and attributes are common to two or more classes then a

    common super class can be created that implements the shared features, leaving only

    the specialized features in the sub classes. This transformation of object model is

    called abstracting out a common superclass or common behavior.

    3) Use Delegation To Share Implementation:Use Delegation To Share Implementation:Use Delegation To Share Implementation:Use Delegation To Share Implementation:Inheritance is mechanism for implementing generalization, in which the behavior of

    a superclass is shared by all its subclasses. Sometimes programmer use inheritance as

    an implementation technique with no intention of guaranteeing the same behavior. It

    often happens that an existing class already implements some of the behavior that we

    want to provide in a newly defined class, although in other respect the two classes are

    different. The designer is then tempted to inherited from the existing class to achieve

    part of implementation of the new class. It is discouraged because; this can lead a

    problem if other operations that are inherited provide unwanted behavior.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    10/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    10

    Object Representation:Object Representation:Object Representation:Object Representation:

    Implementing objects is mostly straightforward, but the designer must choose when to

    use primitive types in representing objects and when to combine groups of related

    objects.

    Classes can be defined in terms of other classes, but eventually everything must be

    implemented in terms of built-in primitive data-types, like integer, float, string type.

    For Example :For Example :For Example :For Example :

    The designer must often choose whether to combine group of related objects. The given

    diagram shows two common implementation of 2-dimensional lines, one as a separate

    class and one embedded as attributes within the Point class.

    Diag :Diag :Diag :Diag : Embedded and Explicit ObjectEmbedded and Explicit ObjectEmbedded and Explicit ObjectEmbedded and Explicit Object

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    11/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    11

    Physical PackaPhysical PackaPhysical PackaPhysical Packaging:ging:ging:ging:

    Programs are made of discrete physical units that can be edited, compiled, imported. In

    any large project, careful partitioning of these units into packages is important to permit

    different persons to cooperatively work on a program. Packaging involves the following

    issues:

    1) Information Hiding:Information Hiding:Information Hiding:Information Hiding:One design goal is to treat classes as black boxes, whose external interface is public

    but whose internal details are hidden from view. The designer must decide what

    attributes should be accessible from outside the class. These decisions should be

    recorded in the object model by adding annotationprivateprivateprivateprivateon attributes that are to be

    hidden.

    2) Coherence Of Entities:Coherence Of Entities:Coherence Of Entities:Coherence Of Entities:One important design principle is coherencecoherencecoherencecoherenceof entities. An entity, such as a class, an

    operation, or a module, is coherent if it is organized on a constant plan and all its

    parts fit together towards a common goal. An entity should have a single major theme;

    it should not be a collection of unrelated parts.

    3) Constructing Modules:Constructing Modules:Constructing Modules:Constructing Modules:During system analysis and design phase we partitioned the object model into

    modules. This initial organization may not be suitable or optimal for the final

    packaging of the system implementation. The new classes that we have added during

    design either add to an existing module or layer or can be organized into a separate

    module or layer that did not exist in the analysis.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    12/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    12

    Documenting Design Decision:Documenting Design Decision:Documenting Design Decision:Documenting Design Decision:

    The design decision must be documented when they are made, or you will become

    confused. This is especially true if you are working with other developers. It is impossible

    to remember design details for any nontrivial software system, and documentation is

    often the best way of transmitting the design to other and recording it for reference

    during maintenance.

    The Design Document should be an extension of the Requirement Analysis Document.

    The Design Document will include a revised and much more detailed description.

    The Object Model,The Object Model,The Object Model,The Object Model, should have both graphical form that is Object Model Diagram and

    textual form that is Class Descriptions.

    The Functional Model,The Functional Model,The Functional Model,The Functional Model, will also be extended during the design phase, it is particularly

    important to specify all operation interfaces by giving their arguments, results, input-

    output mappings, and side effects.

    The Dynamic Model,The Dynamic Model,The Dynamic Model,The Dynamic Model, is implemented by location within program code, then structured

    pseudo code for algorithm is needed.

    Despite the seamless conversion from analysis to design, it is probably a good idea to keep

    the Design Document distinct from the Analysis Document. Because of the shift in view

    point from an external users view to an internal implementers view, the design

    document includes many optimizations and implementation artifacts.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    13/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    13

    Structured Analysis /Structured Analysis /Structured Analysis /Structured Analysis / Structured DesignStructured DesignStructured DesignStructured Design(SA/SD)(SA/SD)(SA/SD)(SA/SD)::::

    Structured analysis is a set of techniques and graphical tools that allow the analyst to

    develop a new kind of system specification that are easily understandable to the user.

    SA/SD is a representation of data flow approach in system. The object modeling technique

    (OMT) and SA/SD methodology, both combine the modeling components. SA/SD focuses

    on functional decomposition. A system is viewed as providing one or more functional to

    the end user.

    Summary Of SA/SD Approach :Summary Of SA/SD Approach :Summary Of SA/SD Approach :Summary Of SA/SD Approach :

    SA/SD includes a variety of notation for specifying the software. The various notations for

    analysis phase are:-

    1)1)1)1) Data Flow Diagram (DFD):Data Flow Diagram (DFD):Data Flow Diagram (DFD):Data Flow Diagram (DFD):DFD, describe the transformation of data as it flows through the system. A DFDconsist of process, data flow, actors, and data stores. Various notations are:

    Database or Data Store.

    Actor / Input Output / Class (Object).

    Process.

    Data Flow.

    A DFD containsprocessesprocessesprocessesprocesses that transform data, data flowsdata flowsdata flowsdata flows that move data, actoractoractoractor

    objects that produce and consume data, and data storedata storedata storedata store objects that store data

    passively.

    A DFD recursively divide a complex process into sub diagram, when the resulting

    process is simple, the decomposition stops.

    2)2)2)2) Process Specification:Process Specification:Process Specification:Process Specification:The Process specification is written for each lowest level process. Process

    specification may be expresses with decision table. It is like a flow chart and if-

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    14/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    14

    then-else and switch-case statement that associate condition with actions to

    perform. It has four quadrants:

    ConditionConditionConditionConditionConditionConditionConditionCondition

    AlternativeAlternativeAlternativeAlternative

    ActionActionActionAction Action EntriesAction EntriesAction EntriesAction Entries

    Process specification may also be expressed as Pseudo code.

    3)3)3)3) Data Dictionary:Data Dictionary:Data Dictionary:Data Dictionary:Data Dictionary contains details which are missing from DFD. It is telling the

    database how to handle each column. The data dictionary defines data flows and

    data stores and the meaning of various attributes.

    4)4)4)4) EEEE----R Diagram:R Diagram:R Diagram:R Diagram:E-R Diagram highlights the relationships between data stores that otherwise

    would be only be seen in the process specifications. There are three basic notation

    in ER model:

    i) Entities : are the things.ii) Attributes : are the data about entities.iii) Relationship : provide the structure between entities.ER diagrams are readily translated into a database implementation

    The above tools are used during the process of structured analysis; Structured Designfollows structured analysis and addresses low-level details. Data flow diagram processes

    are converted into programming language functions, and a structure chart is created

    showing the procedure call tree.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    15/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    15

    Jackson Structured Model (JSD) :Jackson Structured Model (JSD) :Jackson Structured Model (JSD) :Jackson Structured Model (JSD) :

    JSD is a methodology which has different style compared to SA / SD and OMT. The JSD methodology was developed by Michael Jackson. JSD divide the system development into two stages:

    o Specification, and theno Implementation.

    JSD first determines the what and then the how . JSD is useful for the applications in which time is important. JSD uses graphical model but less graphical oriented than SA / SD and OMT.

    Summary :Summary :Summary :Summary :

    A JSD model describe the real world in terms of entities, actions and ordering ofactions.

    Entities appear as noun in requirement statements and action appear as verb. JSD

    software development consists of six sequential steps:

    1)1)1)1) Entity Action :Entity Action :Entity Action :Entity Action :During entity action step, the software developer find out entities and actions.

    The input for entity-action step is requirement statement and the output is list

    of entities and actions.

    2)2)2)2) Entity Structure:Entity Structure:Entity Structure:Entity Structure:During entity structure step, find the order of action of each entity by time.

    3)3)3)3) Initial Model:Initial Model:Initial Model:Initial Model:In initial model step, state how the real world connect to the model. JSD

    support state vector and data storing connection.

    4)4)4)4) Function:Function:Function:Function:The function step uses Pseudo code for output of action. At the end of this step,

    the developer has complete specification for the required system.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    16/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    16

    5)5)5)5) System Timing:System Timing:System Timing:System Timing:In system timing step we consider, how much the model is permitted to log the

    real world.

    6)6)6)6) ImplementaImplementaImplementaImplementation:tion:tion:tion:In implementation step we focus on the problem of process scheduling andallocate processors to process.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    17/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    17

    Mapping Object Oriented Concept using NonMapping Object Oriented Concept using NonMapping Object Oriented Concept using NonMapping Object Oriented Concept using Non----Object OObject OObject OObject Orientedrientedrientedriented

    Language:Language:Language:Language:

    1)1)1)1)

    ENCAPSULATION:ENCAPSULATION:ENCAPSULATION:ENCAPSULATION:On the data side of the world, procedural language structures group data elements into

    larger units which can then be handled as single entities. One structure can include

    others, so a complex arrangement of information can be built from simpler layers.

    2)2)2)2) PACKAGE :PACKAGE :PACKAGE :PACKAGE :In modern non object oriented language, the field of a structure lives in their own name

    space that is; their names wont conflict with identical name data elements outside the

    structure.

    3)3)3)3) REUSABILITY:REUSABILITY:REUSABILITY:REUSABILITY:On the procedural side of the world, functions encapsulate behaviors that can be used

    repeatedly without being reimplemented. Functions can call other functions, so complex

    behaviors can be built from smaller pieces. Functions are reusable, once defined they can

    be called any number of times.

    4)4)4)4) ABSTRACTION :ABSTRACTION :ABSTRACTION :ABSTRACTION :Structures and functions are also able to express significant abstractions, but they

    maintain the distinction between data and operations.

    5)5)5)5) DATA HIDING:DATA HIDING:DATA HIDING:DATA HIDING:Data hiding means, completely hiding the data structure so that it doesnt even have to be

    passed between the functions.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    18/24

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    19/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    19

    the call. This means that changes made to the parameter will affect the argument used to call the

    subroutine. As you will see, Java uses both approaches, depending upon what is passed.

    Example : Call By Value:Example : Call By Value:Example : Call By Value:Example : Call By Value:

    class Test {

    static void doubleData(int x) {

    x = x+x;}

    }

    class CallByValue {

    int i;

    public static void main(String [] ar) {

    CallByValue ob = new CallByValue();

    ob.i = 20;

    System.out.println("BEFORE : "+ob.i);Test.doubleData(ob.i);

    System.out.println("AFTER : "+ob.i);

    }//End Of Main

    } //End Of CallByValue

    Example : Call ByExample : Call ByExample : Call ByExample : Call By ReferenceReferenceReferenceReference::::

    class Test {

    static void doubleData(CallByReference ob) {

    ob.i = ob.i + ob.i;

    }

    }

    class CallByReference {

    int i;

    public static void main(String [] ar) {

    CallByReference ob = new CallByReference ();

    ob.i = 20;

    System.out.println("BEFORE : "+ob.i);Test.doubleData(ob);

    System.out.println("AFTER : "+ob.i);

    }//End Of Main

    } //End Of CallByValue

    OUTPUT:OUTPUT:OUTPUT:OUTPUT:

    BEFORE : 20

    AFTER : 20

    OUTPUT:OUTPUT:OUTPUT:OUTPUT:

    BEFORE : 20

    AFTER : 40

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    20/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    20

    Implementing Inheritance:Implementing Inheritance:Implementing Inheritance:Implementing Inheritance:There are several ways to implement data structures for inheritance in a non-object-

    oriented language:

    Avoid itAvoid itAvoid itAvoid it:::: Many applications do not require inheritance. Many other applicationshave only a few classes requiring inheritance. Those classes not needing inheritance

    can be implemented as simple records.

    Flatten the class hierarchy:Flatten the class hierarchy:Flatten the class hierarchy:Flatten the class hierarchy: Use inheritance during design but expand each concreteclass as an independent data structure during implementation. Each inheritance

    operation must be re-implemented as a separate method on each concrete class.

    Break out separate object:Break out separate object:Break out separate object:Break out separate object: Instead of inheriting common attribute from a super class,a group of attribute can be pulled out of all the subclasses and implemented as a

    separate object with a reference to it stored within each subclass.

    These approaches avoid the implementation of inheritance. When inheritance is

    actually needed, the best implementation depends on the language.

    Implementation Inheritance In C :Implementation Inheritance In C :Implementation Inheritance In C :Implementation Inheritance In C :To handle single inheritance, embed the declaration for the super class as the first

    part of each subclass.

    The class Shape is an abstract class, with concrete sub classes Box and Circle. The C

    declaration for classes Shape, Box, and Circle are as follows:struct Shape{struct Shape{struct Shape{struct Shape{

    struct ShapeClass *class;

    Length x;

    Length y;

    };};};};

    struct Box{struct Box{struct Box{struct Box{

    struct BoxClass *class;

    Length x;

    Length y;

    Length width;

    Length height;

    };};};};

    struct Circle{struct Circle{struct Circle{struct Circle{

    struct CircleClass *class;

    Length x;

    Length y;

    Length radius;

    };};};};

    A pointer to a Box and Circle structure can be passed to a C function expecting a

    pointer to a Shape structure because the first part of the Box and Circle structure is

    identical to the Shape structure.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    21/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    Implementing Association:Implementing Association:Implementing Association:Implementing Association:Associations are the glue of our object model, providing access paths between objects.

    During object design phase we must formulate a strategy for implementing the associations in

    the object model. To make intelligent decision about associations, we first need to analyze the

    way they are used.

    Analyzing Association Traversal :Analyzing Association Traversal :Analyzing Association Traversal :Analyzing Association Traversal :We have assumed now that associations are inherently bi-directional, which is certainly true

    in an abstract sense. But if some associations in our application are only traversed in one-

    direction, their implementation can be simplified.

    Types Of Associations :Types Of Associations :Types Of Associations :Types Of Associations : OneOneOneOne----Way AssociationsWay AssociationsWay AssociationsWay Associations ::::

    If an association is only traversed in one direction, it may be implemented as areference in object that is an attribute which contains the reference of an associated

    object. If the multiplicity is one the it is a simple reference, and if the multiplicity is

    many then is a collection reference may be Array, ArrayList, Set etc.

    TwoTwoTwoTwo----Way Associations :Way Associations :Way Associations :Way Associations :Many associations are traversed in both directions, although not usually with

    equal frequency, it may be implemented as attribute in both directions. This approach

    permits fast access, but if either attribute is updated then the other attribute must also

    be updated to keep the link consistent.

    Implementing Association In Java :Implementing Association In Java :Implementing Association In Java :Implementing Association In Java :

    One WayOne WayOne WayOne Way Traverse:Traverse:Traverse:Traverse: OneOneOneOne totototo One AssociationOne AssociationOne AssociationOne Association

    class Person {class Person {class Person {class Person {

    int personId;

    int personName;

    PersonDetail details;PersonDetail details;PersonDetail details;PersonDetail details;

    }}}}

    cccclass PersonDetail {lass PersonDetail {lass PersonDetail {lass PersonDetail {

    Date dob;

    String address;

    String contact;

    String occupation;

    }}}}

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    22/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    Object Oriented Programming Style:Object Oriented Programming Style:Object Oriented Programming Style:Object Oriented Programming Style:Good programs do more than simply satisfy their functional requirements. Programs that

    follow proper design or programming style are more likely to be correct. We present object-

    oriented style guidelines under the following categories:

    1)1)1)1) RESUABILITY :RESUABILITY :RESUABILITY :RESUABILITY :Reusable software reduces design, coding, and testing efforts over several design. Reuse

    is possible in conventional language, but object oriented languages enhance the

    possibility of code reuse.

    Types Of Reusability:Types Of Reusability:Types Of Reusability:Types Of Reusability:There are two kinds of reuse :

    (i) Sharing of newly-written code.(ii) Reuse of previously written code.

    Style Rules for ReusabStyle Rules for ReusabStyle Rules for ReusabStyle Rules for Reusabiiiility:lity:lity:lity:(i) Keep methods coherent.Keep methods coherent.Keep methods coherent.Keep methods coherent. A method is coherent if it performs a single or

    a group of closely related functions.

    (ii) Keep methods small.Keep methods small.Keep methods small.Keep methods small. If a method is large, break it into smaller methods.By breaking a method into smaller parts, we may be able to reuse some

    part even when the entire method is not reusable.(iii) Keep methods consisKeep methods consisKeep methods consisKeep methods consistent.tent.tent.tent. Similar methods should use the uniform

    structure including name, condition, arguments order and types, return

    type and error condition.

    (iv) Provide Uniform CoverageProvide Uniform CoverageProvide Uniform CoverageProvide Uniform Coverage If input conditions can occur in variouscombinations, write methods for all combination.

    Using Inheritance :Using Inheritance :Using Inheritance :Using Inheritance :(i) Subroutine :Subroutine :Subroutine :Subroutine : The simplest approach is to factor out the common code into

    a single method that is called by each method.

    (ii) Factoring :Factoring :Factoring :Factoring : In some cases the best way to increase code reuse betweensimilar classes is to factor out the differences between the methods of

    different classes, leaving the remainder of the code as a shared method.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    23/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    2)2)2)2) EXTENSIBILITY :EXTENSIBILITY :EXTENSIBILITY :EXTENSIBILITY :Most software is extended in ways that its original developers may not expect. The

    following object oriented principles enhance extensibility.

    Encapsulate Classes :Encapsulate Classes :Encapsulate Classes :Encapsulate Classes : A class is encapsulated if its internal structure is hiddenfrom other classes. Only methods on the class should access its implementation.

    Hide Data Structure :Hide Data Structure :Hide Data Structure :Hide Data Structure : Do not export data structure from a method. Internal datastructures are specific to a methods algorithm. If you export them, you limit

    flexibility to change the algorithm later.

    AvoidAvoidAvoidAvoid Case Statement On Object TypeCase Statement On Object TypeCase Statement On Object TypeCase Statement On Object Type :::: Use method instead. Distinguish public and private Operations :Distinguish public and private Operations :Distinguish public and private Operations :Distinguish public and private Operations : Public operation are visible outside a

    class and have published interfaces. Once a public operation is used by other

    classes, it is costly to change its interface, so public operation should mecarefully defined. Private operations are internal to a class and are use to help

    implement the public operation.

    3)3)3)3) ROBUSTNESS :ROBUSTNESS :ROBUSTNESS :ROBUSTNESS :A method is robust if it does not fail even if it receives improper parameters. Robustness

    against internal bugs may be traded off against efficiency. Robustness against user

    errors should never be sacrificed.

    Guidelines to design a robust computer application: Protect against errorsProtect against errorsProtect against errorsProtect against errors by validating user input. Perform code optimizationcode optimizationcode optimizationcode optimization after the program runs or start working. Perform argument validationargument validationargument validationargument validation on external operations those available to user of

    the class to prevent failure.

    In case of dynamic memory allocation to create data structure we should avoidavoidavoidavoidpredefined limitspredefined limitspredefined limitspredefined limits.

    Instruction the program for debugging and performance monitoring.

  • 7/30/2019 Object Oriented Technic Notes(Unit3)

    24/24

    Content Developed by : Mr. Faiz Mohd Arif Khan & Mr. Bhanu Pratap Rai

    ProgrammingProgrammingProgrammingProgramming----InInInIn----Large :Large :Large :Large :Programming in large refers to writing large, complex programs with team of

    programmers. Human communication becomes paramount on such projects and requires

    proper software engineering practices. The following guidelines should be observed:

    Do noDo noDo noDo not prematurely begin programmingt prematurely begin programmingt prematurely begin programmingt prematurely begin programming All software development methodologyemphasis on the importance of first designing, the coding.

    Keep methods understandableKeep methods understandableKeep methods understandableKeep methods understandable A method is understandable if some other than thecreator of the method can understand the code.

    Make methods readableMake methods readableMake methods readableMake methods readable Meaning full names of methods and its variable increasereadability.

    Use exactly the sUse exactly the sUse exactly the sUse exactly the same name as in the object modelame name as in the object modelame name as in the object modelame name as in the object model - The choice of name of Classes,method and variable should be exactly same as declared in object model.

    Documents classes and methodsDocuments classes and methodsDocuments classes and methodsDocuments classes and methods Everything should be documented, classdocumentation should describe its attributes & methods, and method documentation

    describes its purpose, functionality, context, input and output.

    Publish the specificationPublish the specificationPublish the specificationPublish the specification The specification is a contract between the producer andthe consumer of class. The specification only contains declarations.