Here is the simple, short and easy stuff on the basic concepts of OOP. You’ll find these concepts very easy after reading it.
Before Object Oriented Programming
In earlier days, the computer program was a long list of commands. The commands were then grouped into the list of commands called the functions. All the data was in one location and it was modified from everywhere, which caused the problems and issues, as data modified in one function would affect the other functions too.
If was difficult to identify and fix the bugs. Changing these programs was a nightmare.
Coming to the object oriented programming, the data and commands are put into the discrete objects. The data is hidden within the objects and other classes are not allowed to access the data directly.
Let’s discuss the object oriented concepts encapsulation, polymorphism and inheritance.
Encapsulation
The first one is encapsulation. It hides the internal state of one object from the others. It conceals the details. For example to drive a car, we need to know how to accelerate, break and steer. The car does not need to tell us about how it burns the fuel, how it rotates the tires or how it performs the things. This information is hidden from the driver. It only focuses on what to do which means it will drive us to a destination.
Polymorphism
Polymorphism is the ability of one object to be treated and used like another object. For example, we treat duck as an animal and not just as a duck. Similarly we treat dog and cat also as animals.
Inheritance
Inheritance is an “is-a” relation, which inherits the attributes and behaviors from its parent class. For example, dog is an animal. It means animal is a parent class and Dog is the child class. The child class “Dog” inherits the attributes like age and weight from the parent class , which is an animal. The inheritance allows the child class to inherit the attributes and behaviors of its parent.
Advantages of object oriented programming are, as shown below.
- Modularity
One of the advantages of the object oriented languages are they are modular, which means it is easy to change one module without affecting the other.
- Information-hiding
Information is hidden from the other objects and it is easy to change the internal state without affecting the external interface.
- Code re-use
Object oriented programming promotes the code reuse.
- Extensibility
Extensibility in an object oriented programming is easy. New functionality is easy to add without affecting existing functionality.
There are some minor disadvantages of object oriented programming.
- Object oriented programs are hard to develop. Real world problems don’t always fit into the objects.
- For smaller programs, it may be easier to use the list of commands rather than a full blown object oriented program.
- Functional languages and the Structured Query Languages (SQL) are some of the alternatives and they are better suited for certain problems over the object oriented paradigms.
- One needs to be rational, as it is very important to learn the basics of an object oriented design and carefully chose the approach.
Summary
We learned that the object oriented programs were designed to reduce the complexity and improve manageability. Data and operations are gathered into the discrete objects. We also learned pros and cons of object oriented programming.
Source Click
here for the actual resource.