Ch-5 Object Oriented Programming
Definition of Object Oriented Programming (OOP): - OOP is a programming paradigm in which emphasis is given on data rather than process. - OOP allows decomposition of a problem into a number of entitles called objects and then builds data functions around these objects. - C++, Java, C#, Visual Basics are popular OOP languages. Features of Object Oriented Programming: • Emphasis is on data rather than procedures. • Programs are divided into objects. • Data structures are designed such that they characterized the objects. • Functions that operate on the data of an object are tied together in the data structures. • Data is hidden and cannot be accessed by external functions. • Objects may communicate with each other through functions. • New data and functions can be easily added whenever necessary. • Bottom-up approach is followed in program design. Objects: An object is any entity, thing or organization that exists in real world. It consists of two fundamentals characteristics: its attribute and behaviors. For example: a dog is object which have attributes such as color, weight, age, type etc. and behaviors such as barking, wagging tail etc. In OOP, attributes are represented by data (variables) and the behaviors are represented by the functions. An object can communicate with others by using message passing mechanism. Objects are the basic run time entities in an object oriented system which may be created or destroyed at run time. In OOP, the problem is divided into a group of objects and each object consists of own properties (data) and behaviors (functions). The data and function containing in an object is called its member data and member function. The member function of an object can only access its data. The basic concept behind OOP is to integrate both data and function into a single entity. This entity is also called object. Class: A class is the collection of similar objects. In fact objects are variables of type class. So, it is defined as the template or prototype which contains the common attributes and behavior for all the objects of the class. In programming language, the entire set of data and code of an object can be made a user-defined data type with the help of class. Once a class has been defined, we can create any number of objects associated with that class. For example, mango, apple and orange are members of class fruit. If fruit has been defined as a class, then the statement fruit mango will create an object mango belonging to the class fruit. There are three areas of class: public, private and protected. So, class incorporates the concept of data hiding. The functions and variables defined inside public area can be accessed by any object. The functions and variables defined inside private area can be accessed by the object of the same class and protected area can be accessed by the object from the same class and derived class. Defining class doesn’t create an object but class is the description of object’s attributes and behaviors. So no memory is allocated when class is created. When object is created then only memory is allocated. Data Abstraction & Encapsulation : In OOP, abstraction defines the conceptual boundaries of an object. These boundaries distinguish an object from another object. So, abstraction is the act of representing essential features without including the background details. It focuses the outside view of an object, separating its essential behavior from its implementation. To understand this concept more clearly, take an example of 'switch board'. We only press particular switches as per our requirement. We need not know the internal working of these switches. What is happening inside is hidden from you. This is abstraction, where we only know the essential things to operate on switch board without knowing the background details of switch board. POINTS TO REMEMBER Data abstraction refers to the conceptual boundaries of an object. So, abstraction is the act of representing essential features without including the background details. Encapsulation is a way of organizing data and function into a structure (called class) by concealing (hiding) the way the object is implemented, that is preventing access to data by any means other than those specified. Encapsulation therefore guarantees the integrity of the data contained in the object. It implies that there is visibility to the functionalities offered by an object, and no visibility to its data. The best application of encapsulation is making the data fields private and using public access of functions. However, we cannot hide an entire object. To use an object, a part of it needs to be accessed by users. To provide this access, abstraction is used. Abstraction provides access to a specific part of data while encapsulation hides the data. Therefore, abstraction and encapsulation complement each other. POINTS TO REMEMBER IEncapsulation is a way of organizing data and function into a structure (called class) by concealing (hiding) the way the object is implemented. Inheritance The process of creating a new class from an existing class in which objects of the new class inherit the attributes and behaviors of the existing class is known as inheritance. The newly created class is called derived class or child class or sub-class and the class from which new class is created is called base class or parent class or super class. POINTS TO REMEMBER IThe process of creating a new class from an existing class in which objects of the new class inherit the attributes and behaviours of the existing class is known as inheritance. The relationships of classes through inheritance give rise to a hierarchy. So, inheritance models the natural hierarchical classification of real world system. It permits the expansion 5.3 Advantages of OOP • We can eliminate redundant codes by using inheritance features of OOP. • It is very easy for managing complex and large size problems. • The more important is the reusability of codes by using the features of inheritance. • It takes very less time for the development and maintaining the software. • It is efficient for testing and implementation of the system. • It follows bottom up approach. • It can be implemented in the field of OODBMS (Object Oriented Database Management System), OOAD (Object Oriented Analysis and Design) and other different fields of engineering. 5.4 Application of OOP The concept of object helps to translate our thoughts to a program. It provides a way of solving a problem in the same way as a human being perceived a real world problem and finds out the solution. It is possible to construct large reusable components using object-oriented techniques. Development of reusable components is rapidly growing in commercial software industries. If there is complexity in software development, object oriented programming is the best paradigm to solve the problem. The following areas make the uses of OOP. • Image processing and pattern recognition • Computer aided design and manufacturing • Object Oriented Database Management System • Internet and Web based Applications • Mobile Computing • Data Warehouse and Data Mining • Digital Electronics Differences between OOP and Structured Programming Language
Object Oriented Programming Language | Structured Programming Language |
---|---|
(i) OOP focuses on representing problems using real-world objects and their behaviors. (ii) Large programs are divided into objects. (iii) It uses bottom up approach of program development. | (i) Structured programming language deals with organizing the program in a logical structure. (ii) Large programs are divided into functions. (iii) It uses top down approach of program development. |
OOP (Object Oriented Programming)