- GETTING STARTED
- BASIC JAVA
- JAVA STRINGS
- EXCEPTION HANDLING
- JAVA 9
- EFFECTIVE JAVA
Now that you know about Class and Object , lets get back to our programming style which is Object oriented. A language is object-oriented if and only if it satisfies the following requirements:
A programming style is "a way of organizing programs on the basis of some conceptual model of programming and an appropriate language to make programs written in the style clear".
A software system may consist of many classes. But in any case, when you have many, it needs to be managed. Think of a big organization, with its work force exceeding several thousand employees (let's take one employee as a one class). In order to manage such a work force, you need to have proper management policies in place. Same technique can be applies to manage classes of your software system as well. In order to manage the classes of a software system, and to reduce the complexity, the system designers use several techniques, which can be grouped under four main concepts:
We have to admit, there are some of us who tends to forget what are the
4 pillars of OOP or what is their technical explanation. If you are like me, who tends to use them a lot but always can't find the words to explain it to friend or a colleague or your cousin then this is something worth your time recalling.
Abstraction is the process of hiding out the working style of an object and showing only the required information of the object in understandable manner.
Let's discuss it with the help of an example of Car.
You know that you need to put on the keys, change the gear and accelerate in order to drive a car but do you actually know what happens when you change the gear and accelerate, or say how the car engine works? You don't, and that's simple because you don't need to know all that complexity. Your Job is to just drive the car. That's what we call Abstraction.
Encapsulation means wrapping up data and member function (Method) together into a single unit i.e. class. Encapsulation automatically achieve the concept of data hiding providing security to data by making the variable as private and expose the property to access the private data which would be public.
Let's discuss Encapsulation with an example of your school Bag in which you keep all your stuff like books and pens and document etc. to keep it safe from the outside world. Here you are hiding your books and pen by putting them inside the Bag similarly in OOP we encapsulate the data and methods inside the class to keep it safe and accessible only to authorized member.
Poly=many morph= form
By name we can come to a conclusion that it's about something with many forms. In OOP it is an ability of an object to take many forms.
A subclass can have their own behavior and share some behavior from its parent class BUT!! not vice versa. A parent class cannot have the behavior of its subclass.
Let's learn with the help of an example:
My name is Vivek: I am a husband, a brother, a friend, a son, a student depending upon the situation i.e. parameter surrounding me.
Another example, Twin brothers looks alike but they hold different characters.
Similarly in OOP we can have a function with different form but with same name.
The ability of creating a new class from an existing class. Inheritance is when an object acquires the property of another object. Inheritance allows a class (subclass) to acquire the properties and behavior of another class (superclass). It helps to reuse, customize and enhance the existing code. So it helps to write a code accurately and reduce the development time.
For example, a secintific calculator is an extended form of Caluculator, here Caluculator is parent and secintific calculator is Child object.
Another example, a convertible car and 4x4 car are the extended form of car.
In the coming chapters you will learn all 4 pillars in detail.