What is OBJECT-ORIENTED PROGRAMMING.
- INTRODUCTION– C++ is an OBJECT-ORIENTED PROGRAMMING (OOP) like java language. The object-oriented programming approach has attempted to handle the large complexities in the program giving more reliable, clear and easily maintainable products. The OOP approach has a wide range of application like artificial inelegancy, normal networks, simulation and real-time system. C++ is today’s dominant computer language because of its striking features like data encapsulation, polymorphism, inheritance.
- PROCEDURE ORIENTED PROGRAMMING(POP)– Procedure-oriented language contains lists of instruction and instruction tells the computer to do something such as reading, writing, and calculation.
- MAIN CHARACTERISTICS OFP PROCEDURE-ORIENTED PROGRAMMING —
1.DIVISION INTO FUNCTION– In this approach, a large program is divided into functions has a clearly defined propose and interface for other function.
2) GLOBALIZATION OF DATA– In procedure ORIENTED language, the primary focus is on function and less importance is given to data. Data is made global so that it can easily be accessed by every function.
NOTE– C and Pascal support local data also.
3) NEW DATA TYPE– It is very difficult to create new data types like complex data types. POL does not support extensibility.
3) RELATIONSHIP TO THE REAL WORLD– It does not model real world problem very well.
MAIN FEATURES OF PROCEDURE-ORIENTED PROGRAMMING–
- Follows structured programming approach.
- Function oriented, less importance to data.
- Globalization of data leads to loss of importance information.
- Do not model real world ver well.
- Follows top down approach.
- Example C, FORTMAN, Pascal.
- OBJECT-ORIENTED PROGRAMMING– Object oriented programming approach binds the data and the function that operate on that data into a single entity is called an object. Functions of an object can only access its data. Thus, object-oriented programming language model around ‘objects’ rather than ‘actions’ and ‘data’ rather than logic.
OOP treats data as an important and critical element in the program development. It has data more closely to the functions that operate on it and thus avoid global access. In our real life, we encounter various objects like a chain, pen, mobile, TV, Desk etc. Thus, object-oriented programming revolves around real life.
MAIN FEATURES OF OBJECT ORIENTED PROGRAMMING–
- OOP is more data oriented.
- Programs are made up of objects which model the real world.
- Data and Functions are bonds together.
- Data security exists.
- Objects Communicate through Functions.
- The addition of new data and function is easy.
- OOP follows a bottom-up approach.
- Example- C++, JAVA, .NET.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING–
- OBJECTS– In object-oriented programming, a program is divided into objects, In our day to day life, we come across a number of objects. Some Examples are TV, Telephone, Car.
Each object has the following two characteristics–
- State or Attributes– The state or attributes refers to built-in characteristics of an object. Example– A color TV has the following attributes.
- Volume Control.
- picture Control.
- 75 Channels.
- Remote Control Unit.
- Behavior or Operations– The operations of an object refers to its action. Example– A TV can have following operations.
- Switched ON.
- Switched OFF.
- Displays Pictures.
- CLASSES– A Class is a group of objects that share common properties and relationships. Classes are user defined data types and behave like the built-in types of programming. Objects are variables of the class of the type. Example– A class fruit has mango, apple, and banana as objects. Classes are the basic building block of object-oriented programming.
- DATA ABSTRACTION– Abstraction refers to the act of representing essential features without including the background details or explanations. Example– A TV user can switch on the TV set and enjoy the various TV program without knowing its complete technical details.
- DATA HIDING– Data Hiding is a property, where the internal data structure of an object is hidden from the rest of the program. Thus, the private parts of the objects are not available outside the objects and cannot be altered by external changes.
Data hiding is implemented in C++ with the help of private and protected keywords.
- ENCAPSULATIONS– The wrapping up of data and functions into a single unit is known as ENCAPSULATION is the most fundamental concept of OOP’s. The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. Thus Functions provide the interface between the object’s data and the program.
Encapsulations is i mplemented in C++ with the help of classes.
- ADVANTAGES OF ENCAPSULATION–
- Data Security is not accidentally corrupted by the external world.
- It ensures that changes to data and functions of an object can be made without affecting other objects.
- Objects are independent of each other. Therefore, each object can be studied properly for better understanding the design.
- RELATION BETWEEN ENCAPSULATION AND DATA ABSTRACTION.
- 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. The principle of inheritance is that each derived class from which it is derived.
NOTE- The main advantages of inheritance is reusability means that we can add additional features to an existing class without modifying it. The new class will have features of both classes.
- THE NEEDS AND OBJECTIVE IN INHERITANCE
- It is required for extending the functionality of an existing class.
- It can be used to establish ‘A KIND OF ‘ relationship.
- It helps in reusing class by derived class.
- POLYMORPHISM- In simple terms, polymorphism means one name and many duties. Polymorphism refers to the ability of one thing to take many (poly) distinct forms (morphism).
NOTE- The process of making an operator exhibit different behavior in different instances is called operator overloading.
- TYPES OF POLYMORPHISM- There are two types of polymorphism.
- COMPILE TIME POLYMORPHISM- Binding the code associated with the function call at compile time is known as compile time polymorphism. Function overloading implements compile time polymorphism.
- RUNTIME POLYMORPHISM- Binding the code associated with a function at runtime is called runtime polymorphism. Virtual functions implement this.
- FUNCTION OVERLOADING- Function overloading refers to the use of one function name to perform different parameters type lists, The compiler will regard them as different functions.
To correctly implement functions overloading, The parameters lists must contain either different numbers of parameters or there must be at least one position in their parameter lists, where the type are different. The correct functions to be invoked is determined by checking the number and types of arguments.
- NOTE- Function overloading can be done for functions.
- Having a different type of arguments.
- Having different numbers of arguments.
- ADVANTAGES OF FUNCTIONS OVERLOADED-
- The program becomes easy to read.
- The programmer need not waste time in searching for a new name for similar functions.
- The programmer can devote more time to logic development and need not remember different names.
- Easy maintainable of the code.
- A better understanding of the relation between program and outside world.
- ABSTRACT CLASS– Abstract class is a class that defines an interface but does not necessarily provide the implementation for all its member. No object of an abstract class exists.
- CONCRETE CLASS– A concrete class is a derived class of an abstract class that implements all the missing functionality. A concrete class can be instantiated.
- APPLICATION OF OPPs–
- Artificial intelligence and expert System.
- Neural Network.
- Real-time System.
- Simulation and modeling.
- Object Oriented Database.
- Office automation System.
- CAD/CAM system.