O.O.P. is favoured so much as it overcomes the limitations of other programming paradigms. LIMITATION OF PROCEDURAL PROGRAMMING- As it focuses on the procedure taken rather than the data, it is susceptible to design changes and leads to increased time and cost overheads during these. It doesn’t incorporate data reusability. LIMITATION OF OBJECT BASED PROGRAMMING- It is a subset of OOP, but, it fails to represent real world relationships that exist b/w objects as it doesn’t incorporate “inheritance”. Why Object Oriented Programming ?
HOW DOES O.O.P. WORK
The concepts that O.O.P. incorporates helps it work on the limitations of other programming paradigms. These are-
The general concepts of Object Oriented Programming concepts in C++
DATA ABSTRACTION Definition- The act of representing essential features without including the background details or explanations. Levels of abstraction- Physical level: The lowest level of abstraction describes how a system actually stores data. Logical level: The next higher level of abstraction describes what data the database stores, and what relationships exist among those data . View level: The highest level of abstraction describes only part of the entire database
Diagram showing the levels of abstraction
Example of Data Abstraction A Sales Person Real world Genetic history Name Cars sold Talents Credit record Family Commission rate Medical history
Example of Data Abstraction A Sales Person Cars sold Name Commission rate Abstraction for sales tracking system
DATA ENCAPSULATION Definition – The wrapping up of data and functions into a single unit (which is called class). Encapsulation means that some or all of an object's internal structure is "hidden" from the outside world. Hidden information may only be accessed through the object's methods, called the object's public interface. Access to object is safe, controlled.
Example of Data Encapsulation HR dept. Accounts Dept. Purchase dept. Production dept. Sales dept. . Head of dept. Supervisors Workers Clerks Records and folders Internal structure of dept. Quality Dept. Various departments of a company
Encapsulation for class builders and class users.
It is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.
It reduces the complexity to some degree.
It creates a number of well-defined, documented boundaries within the program (known as sub-routines).
How it is implemented in C++ -
In C++, it is implemented through separately compiled files, namely, the header files. These can be used in programs through the #include directive.
Example of Modularity Home theatre Even though the parts of the home theater are complete units in themselves, yet they are a subpart of the home theater.
Example of Modularity in C++ The use of data as is also modularity.
It is the capability of one class to inherit capabilities or properties from another class.
It ensures closeness with the real world.
It implements the idea of reusability.
It is transitive in nature.
If a class B is inheriting from another class A and class C is inheriting from class B (thus, A becomes the base class).If we later find a mistake in class A and rectify it, it is automatically reflected in the classes B and C too. This reduces overhead costs and time which were a major problem in Procedural Programming.
Example of Inheritance Vehicles Automobiles (motor driven) Pulled vehicles Rickshaw Cart Bus Car
POLYMORPHISM Definition- The ability for a message or data to be processed in more than one form The simplest way to define it is- “ ONE ENTITY, MANY FORMS ” Means the same name can be assigned to different functions/methods : the actual function triggered by the name is determined by the types of the arguments. It is sometimes called overloading . It allows designers to use the most "natural" and understandable names for functions. Example-
Example of Polymorphism Mammals Mammals Whale Man Dog Rat Cat Rat Cat See through daylight See through darkness
Polymorphism for class builders and class users.
Advantages and disadvantages of Object Oriented Programming concepts
Advantages of OOP
Q uick development as parallel development of classes is possible.
E asier to test manage and maintain
E asy to understand.
M odels the real world well.
Disadvantages of OOP
D esign is tricky.
O verly generalized classes.
P roper planning and design is required
A rtificial at times.
N eeds proper skills such as programming skills, thinking in terms of objects..