In this section we will discuss on Overview of OOPs Concept:
- Basic OOPs concept
- Knowledge on Class
- What is Object
- What is Method and Message passing
- Knowledge on Abstraction, Inheritancem Encapsulation
In the traditional language like C, COBOL, FORTRAN etc, logic is given high priority. Do you think should logic be high priority in every aspect of programming?
Obviously, No. Logic always manipulate Data. So, in current real scenario Data should be the highest priority in programming world. Programmer should concentrate on the security of the data rather logic. Because Logic may be changed or manipulated in different way but Data security should not be compromised in current real scenario. One of the security logic is encapsulation which procedural programming does not support. But OOPs support encapsulation which prevents data to be accessed by any random methods.
Addition to Encapsulation, Code re-usability is another advance concept which not achieved by procedural programming language. With this code can be optimized and secured with communicating with other entity.
To overcome this drawback, first OOPs language came to world named Simula. It introduced most of the features of OOPs like Class, Object, Method, Virtual Method, Inheritance, and Polymorphism. In the programming world, where everything represented as Object is known as Pure Object-Oriented programming language.
Smalltalk is the First Object-Oriented Programming language.
Later other OOPs language come to the programming world, like C++, Java, Python etc. The main objective of Object- Oriented Programming language is to implement real world entities.
Let’s discuss all the OOPs concept in detail.
Class is an abstract concept which contains Data & Methods. In normal language it is nothing but a template and though it Object can be created when it is instantiated. It can be designed by a structural representation of attributes. It does not occupy any memory.
In other word, class is a blueprint from which individual objects can be created.
Object is an instance of a Class. It simulates the Data and Methods and communicate with other Objects.
In real life example, the entity which has state and behaviour is known as Object. E.g. Chair, Pen, Book etc. The property of one object can eb communicated to another object through the corresponding object.
A method is an entity though which an object can interact with the external Object. Object implementation always happens only through the Method.
Communicating from one object to another is known as Message passing. This will be done only through methods in Object-Oriented Programming world.
In normal term, Abstraction implies “Hiding the Details”. It means it hides the details of implementation and showing only the methods or function to interact with the Data without knowing the implementation.
For example: The cell phone users know only the various functionality of the phone but not aware of how it is working in backend.
Now let’s understand the abstraction with the real programming language.
In Object-Oriented Programming language, Abstraction hides the internal implementation details like the Cell Phone Users. You just need to be aware the method name and the parameter details which is acceptable by this method. No need to understand how this method is implemented.
Binding the code and data together into a single unit is known as Encapsulation. What is code and which type of code it should bind. The answer is very simple. It binds the methods or function that manipulate the data.Programming code is the data in this case. In structured programming language like C, FORTAIN, and Data cannot be manipulated by functions or methods which affects the security of the application. But in today’s real-world security of data is the highest priority.
Inheritance is a simple features in which classes are behaves parent & child relationship. You know child has some characteristic of its parents. Similarly, in Java one object acquires features of another along with its own features. The object from which the property is acquired is called Parent and the object which acquires the property of another object is known as child. Parents class also known and super class and the child class is known as sub class.
Polymorphism means “One name and Many Forms”. That means a single method name can perform many task in java. Addition to the name, argument type as well as content of the invoking objects are also important.
Let’s understand this with the Cell Phone example.
In Cell phone you have many feature like phone call, Message, Games etc.
For message feature, if you want to send the message to the recipient then you need two parameters. One is recipient name and type the message. E.g.
Messg send(Text message, recipient name)
If you want to send the MMS message to the application, then you need to change the one parameter i.e. Text message.
If you will implement this two feature independently without polymorphism then you need to use two methods one is send-text() and other is sedn_mms().
But in Polymorphism, you can use the same method and different type of argument to acquire the feature.
send(Text_message, Recipient_name) --> Sending Text message send(MMS_message, Recipient_name) --> Sending MMS message
Polymorphism is of 2 types.
- Static Polymorphism
- Dynamic Polymorphism.
We will discuss briefly on polymorphism in Polymorphism section.
- Class is abstract concept whereas Object is real entity.
- Class does not occupy memory, but Object occupy memory on instantiated.
- Methods are gateway through which attributes can communicate with the other.
- Abstraction is the feature in which internal implementation is hidden.
- Encapsulation is the feature in which information and methods are bind together.
- Polymorphism means “one name and more form”.
- Inheritance facilitates the code reusability. It is possible to create child class and inherit the same functionality from its parent class without using the parent code again in child class.