OOP concept

 OOP Concept

1) Class

  •  The entire set of data, and code of an object can be made a user-defined data type with the help of a class.

  •  In fact, Object are the variables of the type class.
  •  Once a class has been defined , we can create number of objects belonging to that class.

  •  Each object is associated with the data of type class with which they are created.
  •  So, class is a collection of objects of similar type.
  • For example, mango, apple & banana are members of class fruit.
  •  Classes are user-defined data types & behave like the built-in types of a programming language.
  • The syntax of creating an object is no different than the syntax used to create an integer object in c.
  •  If fruit has been defined as a class, then the statement fruit mango;
  •  It will create an object mango belonging to the class fruit.

2) Object

  •  Objects are the basic run-time entities in the object oriented system.
  •  They may represent a person, a place, a table of data, a bank account or any item that a program has to handle.
  •  They also represent user define data.
  •  When a program is executed, the objects interact by sending messages to one another.
  •  For example if “customer” and “account” are two objects in a program then the customer object may send a message to the account object requesting for the bank balance.
  • Each object contains data, code and code to manipulate that data.

3) Encapsulation

  •  The wrapping up of data & functions into a single unit is known as encapsulation.
  •  Data encapsulation is the most striking feature of a class.
  •  The data is not accessible to the outside world & only those functions which are wrapped in the class can access it.
  •  These functions provide the interface between the data of object & the program.
  •  This insulation of the data from direct access by the program is called data hiding or information hiding.
  •  Abstraction refers to the act of representing essential features without including the background details or explanations.
  •  Classes use the concept of abstraction & are defined as a list of abstract attributes such as size ,weight ,cost & functions to operate on these attributes.  They encapsulate all the essential properties of the objects that are to be created.
  •  The attributes are sometimes called data members because they hold information.
  •  The functions that operate on these data are sometimes called methods or member functions.
  • The classes use the concept of data abstraction , they are known as Abstract Data Types (ADT).

4) Inheritance

  •  Inheritance is the process by which objects of one class acquire the properties of objects of another class.

  •  It supports the concept of hierarchical classification.
  • For example , the bird sparrow is a part of the class “flying bird” which is again a part of the class “bird”.
  •  The principle behind this sort of division is that each derived class shares common characteristics with the class from which it is derived as illustrated in fig. :1.4.
  •  In OOP, the concept of inheritance provides the idea of reusability.
  • This means that we can add additional features to an existing class without modifying it.
  • This is possible by deriving a new class from the existing one. 
  • The new class will have the combined features of both the classes.
  • Note , that each sub-class defines only those features that are unique to it.
  •  Without the use of classification , each class would have to explicitly include all of its features

No comments:

Post a Comment