Monday, 5 September 2011


Object Oriented Programming

Talking about the languages we have the following different types of languages as-
  • Structural language- here each program has a well defined structure and format to design and develop it.
  • Object Oriented Language- according to the requirement we develop our program or software.
Elements of Object Oriented Approach-
  • Entity- An entity is something that has a distinct, separate existence.
  • Object- it is a real world entity. It contains information and methods that allow it to be manipulated. Each object has its own identity i.e. two objects are distinct even of their attributes are same. Objects consist of data and functions together. Objects are used for communicating through functions. Objects can be viewed as-

Object- Employee
Data- Emp_Code
           Emp_Name
           Emp_Dob

  • Class- a class is a group of the objects with the same data structure and behavior. In general words class is a collection of similar objects. Normally class is a description of a group of objects with similar attributes common methods, common relationships. Each class describes the possibly infinite set of individual objects and each object is said o be an instance of its class.
  • Attributes- it is a data value held by the objects in a class. Each attribute has a value for each object instance. Attributes are listed in the second part of the class box.  Further a derived attribute is like an attribute in that it is a property of the object itself and computing it does not change the state of the object. It is used to calculate the value during accesses to it.
Object Diagrams- it is a diagram that shows the set of objects and their relationships at a point. It provides a formal graphic notation for modeling objects classes and their relationships to one another. it is useful for both, the abstract modeling and for designing actual programs as-
  • Class diagrams- to describe the classes in graphical notations we use class diagrams.
  • Instance diagrams- the graphical representation of instance of a class can be denoted by it.
 Functionalities of Object Oriented Approach-
  • Data Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
1.      Data Abstraction- By this feature of object oriented programming it is possible to represent the needed information in program without presenting the details. Also by the feature of data abstraction it is possible to create user defined data types and thus increase the power of programming language. Abstraction is the process of exhibiting only the essential characteristics of an object depending on programmers view. It is complement to encapsulation. Here user dose not know how the object is implemented.
  1. Encapsulation- Data Encapsulation is the process of combining data and functions into a single unit called class. By this method one cannot access the data directly. Data is accessible only through the functions present inside the class. Thus Data Encapsulation gave rise to the important concept of data hiding. Data encapsulation, sometimes referred to as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user. The user can only perform a restricted set of operations on the hidden members of the class by executing special functions commonly called methods.
The actions performed by the methods are determined by the designer of the class, who must be careful not to make the methods either overly flexible or too restrictive. This idea of hiding the details away from the user and providing a restricted, clearly defined interface is the underlying theme behind the concept of an abstract data type.
  1. Inheritance- inheritance is the ability to define a new class that is a modified version of a previously defined class. The old class is known as super class and child class is known as sub class. The derived class is called a subclass or child class. The class from which it’s derived is called the super class. Inheritance is the mechanism of sharing attributes and operations among the classes. It may be of-
·        Single inheritance- here we have only one super class as-
 





·        Multiple inheritances- here we have several super classes as-
Class D
 
Class C
 
 

                                                           
 



·        Hierarchical inheritance- here we have one super class and many sub classes.
 





·        Multilevel inheritances- Derived from a derived class come under the multiple inheritances.
 











  1. Polymorphism- same object acting differently or same behavior in different classes acting differently. It is also known as function having many forms. The concept of polymorphism concerns with the different supports the same method. For example the shape () class and their derived classes, triangle, square and circle. The shape class defines the method Draw ().
Links and association- links and associations are the means for establishing relationships among objects and classes. A link is a connection between two classes or between two objects. Two classes are associated by a named relationship. In other words link is a physical or conceptual connection between objects. The links always has the relationship between two or more objects. These are of the-
·        One to one link
·        One to many
·        Many to one
·        Many to many
The object modeling describes as a group of links with common structure and common semantics.  All the links among the object are the forms of association among the same classes. An association relationship may be described as “has a”, “consists of” or “associated with”. Association is used to display communication relationship between two or more classes. It can be defined a general mapping between the classes. The degree of association defines the number of classes connected by association-
  • Unary association
  • Binary association
  • Ternary association
  • Quaternary association
  • Higher order association
Steps to identifying Association- these are steps to identify the association-
Ø  Design the class
Ø  Identify the objects
Ø  Identify the association relationship between objects
Ø  For each relationship identify the rules.
Multiplicity- it denotes the cardinality (mapping) of the association. It specifies how many instances of one class may relate to a single instance of an associated class. There are three types of cardinality as-
  • One to one
  • One to many
  • Many to many
Aggregation- it is a special form of association. An aggregation relationship may be described as “part of” between a whole object and part of objects. We define aggregation relationship as relating an assembly class to one component class. It is the composition of an object out of a set of parts. It has multiple cardinalities. It is a lightly coupled form of association with some extra semantics. The symbol of aggregation is a diamond with a solid line between classes.
Student
 
 


              

Aggregation properties- these are the aggregation properties as-
  • Transitivity
  • Anti symmetric
  • Local modification
Aggregation types- these are the types of aggregation –
  1. Fixed aggregation- it has a fixed structure and number of types and subparts are predefined.
 






  1. Variable aggregation- it has finite number of levels but the number of parts may vary.
 








Generalization- it is the relationship between a class and one or more refined versions of it. The class being refined is called the super class and each refined version is called a sub class. It is sometimes also known as “is-a” relationship because each instance of a sub class is an instance of the super class as well. It is a relationship between a more general element and more specific elements. In another words it is a mechanism for combining similar classes of objects into a single or more general classes. It is the process of minimizing the differences between the entities by identifying the common features. This is the bottom up approach. The notation for the generalization is a triangle connecting a super class to its sub class.
 


Ø  While specialization is a process of defining specialized sub class from a given entity set.
Abstract Class- it is a class that can only be sub classed it can not be instantiated. It is made of one or more abstract methods, which are methods that are declared but do not have method body. Any class that contains one or more abstract methods must also be declared as abstract.  It has no direct instance in the system. Abstract classes are super classes that contain abstract methods and are defined such that concrete subclasses are to extend them by implementing the methods. These classes usually define the common interface for sub classes by specifying methods that all subclasses must override.
Part time
 
Full time
 
Employee
 
Consultant
 
A concrete class has its direct instance in the system objects. We can define any class as a concrete class in the inheritance tree as-

 











Here human is the abstract class where male and female are the concrete class. In this case both male and female classes can share the features of super class human.
Abstract classes are frequently used to define methods to be inherited by sub classes. On the other hand an abstract class can define the protocol for an operation without supplying the corresponding methods and we call this method as abstract method.
Multiple inheritances - it allows a class to inherit attribute operations and associations from more than one super class. It has several super class and one derived class.
 





This contrasts with single inheritance where a class inherits from only one super class. Some times a single class can inherit feature of multiple classes. This is known as multiple inheritances.
Meta Data- it is literally as Data about data, information that describes another set of data. It is the data that is used to describe other data. It describes other data. It provides information about a certain item’s content. So Meta data is often called information about information. It is structured information that describes explains locates or otherwise makes it easier to retrieve use or manage an information resource. So the only difference between data and Meta data is “all metadata is data but not all data is metadata.” There are three types of mete data as per the following-
  • Descriptive metadata- it describes a resource for purpose such as discovery and identification.
  • Structural Meta data- it describes how compound objects are put together.
  • Administrative Meta data- it provides information to help to manage a resource.
Candidate Key- it is combination of one or more attributes that uniquely identifies objects within a class. The importance of candidate keys is that we can identify individual tuples in a relation. Normally it is used in the database field. It is a minimal set of attributes that uniquely defines an object or the link. By minimal we mean that we can not discard an attribute from the candidate key and still distinguish all objects and links. The class may have one or more candidate key. Any candidate key may have any number of attributes. In other words we can say a candidate key is a field that can act as a primary key field for that table to uniquely identifies each record in that table.
Student
S_name
S_rollno
Here for the student class we have two candidates key S_name and S_rollno. A candidate key for an association is a combination of roles and qualifiers which are uniquely identified links. A candidate key is a combination of attributes that can be used to uniquely identify a database record.
Constraints- it is functional relationship between modeling constructs such as classes, attributes and associations. A constraint restricts the value of the data. It also restricts the value that entities can assume. We may place simple constraints in the object model. An object constraint is constraints whose constraints expression is a sentence with one free variable.
Dynamic Modeling- the term combines these models of modeling system. Object model represents the static structure. Dynamic model represents the temporal behavior. Dynamic modeling is the extension of the managed object definition language. In the object model we will describe the system in for of class and relationships. Dynamic model is the collection of multiple behavior diagrams such as state chart, activity, and sequence diagrams. It is concerned with changes to objects and their relationship over time. It shows possible control flows through the system while the object model shows the possible information flows.
Steps to build a dynamic model-
  1. Identify the use case and prepare scenarios of typical sequences.
  2. Identify the events between objects and prepare an event trace diagram for each scenario.
  3. Prepare an event flow diagram for the system.
  4. Develop state diagram for classes with important dynamic behavior.
  5. Check for consistency and completeness of events shard among the state diagrams.
State- it is the attribute values and link held by the objects. It represents the mode of control that has a unique combination of events, conditions actions and next state. It is a condition during the life of an object during which it satisfies some conditions performs some activities or waits for some external events. It is like a manger that knows how to respond to each event according to his rules, laws and procedures. A state describes the result of the object to input events.
Rounded Rectangle: State NameIt is represented as-

Initial state represented as solid circle
Final state represented as- 
               Result
Edges represent the transaction between states and are labeled with an event name.
                                                                          
Example can be as-
Rounded Rectangle: State 2Rounded Rectangle: State 1               Initial State                                                                                   
 



 Result
Event- Event is the specification of the significant occurrence. It is the one way transmission of information from one object to another. It is not like a subroutine call that returns a value. Every event has a unique occurrence. An event has no duration. An event is something that happens between objects. The patterns of event states and state transmission for a given class can be abstracted and represented as a state diagram.
Rounded Rectangle: Light onRounded Rectangle: Light off                                                                                 Button Clicked
 

                                                                                 Button Clicked
Example of events can be as-
  • Mouse button pushed (button, location)
  • Fan switched pressed
  • Motor jammed
  • Airline flight departs( airline , flight number, city)
  • Input string entered( text)
  • Engine speed enters danger zone.
Ø  The sequencing of events at one particular execution of a system is called as Scenarios.
We can say that scenario is the historical record of executing a system that includes all the moment of the system in which any event has occurred. An example can be viewed as-
Scenario for purchasing a shirt:-
  1. Customer arrives at a shop.
  2. Shop keeper asks for service or the item.
  3. Customer requests for the shirts.
  4. Shop keeper brings some shirts.
  5. Shop keeper chooses one shirt.
  6. Customer asks for the price.
  7. Shop keeper replies the price.
  8. Customer gives cash amount for the chosen shirt.
  9. Shopkeeper gives shirts to customer.
  10. Shopkeeper keeps remaining shirts in the shop.
  11. Customer back to his way.
Event Trace Diagrams- the sequence of events- scenario is the first step of dynamic modeling. After writing the scenario we identify the sender and receivers objects of each event. For this we try to make the event trace diagram. Here the time increases from top to bottom but exact time is never shown. This diagram shows both the sequences of events as well as objects-
Customer                                                        Shop                                                    Items
Customer arrives at a shop
Shop keeper asks for service or the item
Customer requests for the shirts                               
                                                                                                  Shop keeper brings some shirts
Ccustomer chooses one shirt
Customer asks for the price
Shop keeper replies the price
Customer gives cash amount for the chosen shirt
Shopkeeper gives shirts to customer
                                                                                                Shopkeeper keeps remaining shirts in shop
Customer back to his way

Operations- An action is an operation in response to an event. It is an executable and atomic computation. Actions may include operations. An action may be instantaneous such as “Switch. On ()” or may be a continuous activity such as “call be mobile”. The operations are like functions that may be applied to the objects in a class. Operations may be attached with states.
Nested State Diagrams- these are the expansions of state diagrams.  These can be structured to permit concise a short description of complex systems. A state diagram relates events and states. The state diagram describes the sequences of state that an object performs in response to events. When an event is received the next state depends on the current state as well as the event. It is normally a form of generalizations on states. The state in the nested diagrams is all refinements of the sate in the high level diagrams but in general the states in a nested state diagram may interact with other states.
 





Ignition
 
Car
 
Concurrency- it shows the set of concurrent objects. A dynamic model describes the set of concurrent objects where each objects having its own state and state diagram. It is a process that arises within the state of an object that can be divided into subsets of attributes or the links. A state of entire system can not be represented by a single state in a single object. It is the product of sates of all objects in it.  Concurrent state diagrams are described by enclosing two state diagrams within a state box. The state box is split by a dashed line at the middle. Following is the example object model of car system.
Transmission
 
Accelerator
 
Brake
 
 



Object model of car system



          
              
An aggregation and its concurrent state diagrams
Advance Concept of Dynamic Modeling- here we find out some of the advance concepts of state diagrams like action, transition, events and activities as per the following-
  1. Entry and exit actions- these are useful in state diagrams. This is an alternative to show actions on the transition. Action can be associated with entering or exiting a state. The exit actions are less common. A state can be expressed in terms of matched entry-exit actions. The process is as follows-
Ø  First all the actions on the incoming transition will be executed.
Ø  Entry action followed by the activity within the state followed any the exit action and finally the action on the outgoing action.
Whenever the state is entered by any incoming transition the entry action is performed. An entry action must be written inside the state box following the key word entry and a “/” character.
Rounded Rectangle: State exit/ actionRounded Rectangle: State entry/ ActionLike an entry action an exit action also shown inside the state box following the keyword exit and a “/” character.


  1. Internal action- when an event can cause then an action to be performed without causing a state change. The event name is written inside state box followed by “/”.
Rounded Rectangle: State event name / Action
 



  1. Automatic transition- this is a transition which is unlabeled in the state diagram. When the activity is completed a transition to another state fires automatically. Such type of unlabeled transition is also called lambda transition.
  2. Sending events- an object can perform action of sending an event to another object. A system interacts by events. An event can be directed to a single or a group of objects. Any and all objects can accept it concurrently. If a state can accept events from more than one object the order in which concurrent events are received may affect final state. This is called a race condition and unwanted race conditions should be avoided.
  3. Synchronization of concurrent activities- sometimes an object must perform two or more activities concurrently. Both activities must be completed before the object can progress to its next state. It includes support for-
Ø  Activity diagrams
Ø  State diagrams
Ø  Sequence diagrams
Dynamic Model Samples- when we are making the dynamic model we have to maintain the following three fundamental procedures-
Ø  Scenario
Ø  Event Trace Diagram
Ø  Event Flow Diagram
Ø  State Diagram

No comments:

Post a Comment