Object Oriented Programming is programming technique involving thinking of software in terms of Objects that interact with each other.
Normally several concepts get associated with this paradigm:
Also terms such as
Encapsulation and Information Hiding
Encapsulation specifies that Objects contain:
- Data via properties.
- Action/Behavior via methods.
The data that is stored inside the Objects can be hidden from other objects.
Yet those objects may still be able to perform actions involving those objects. They do these via methods.
However, the implementation details of those methods as well as the data they are working on are hidden from the outside world.
In some languages like Java and C#, accessibility modifiers are used such as
public to specify the visibility level.
Inheritance allows us introduce Parent-Child relationships to objects. This is a kin to the real world where there always a hierarchical relationship.
Classes are the blueprints for creation of objects. And these classes can inherit from other classes in Object Oriented Programming.
The child inherits methods and properties from parent class.
The child can re-define the inheritted method. We call this method overriding.
Aggregation is also known as composition. It basically involves combining several objects into a new one.
Aggregation allows breaking a problem into smaller and easier to handle parts. A technique generally called divide and conquer.
Aggregation, by it allowing us to break problems into smaller chunks, brings about a higher level of abstraction.
Polymorphism is the ability of calling the same method on different objects, with each of them responding in their own way.
Once you've inherited from a base class, for example, then you can call a method defined in that base class via the base class reference or the child class reference.
And each of those calls may mean different tasks being executed.
Objects are the basis of Object Oriented Programming.
Object Oriented Programming is normally considered powerful yet easier than other paradigms because with objects we can model the real world or concepts.
This then provides with a mental framework for thinking through program design.
The characteristics of that object can then be representated via properties while the actions that the object can take by methods.
Objects are always formed from classes.
A class is a template for object creation. I can create a
Person class for instance then from it create
Matilda and an arbitray number of
We said at the introduction that Objects do contain data and behavior. Well those data and behavior are defined in the class.
Then the instance of that class, which is the object, can obtain those access the properties and those methods which define the data and behavior respcetively.