Object Oriented Programming in Java
Object Oriented Programming is a concept of objects and relating everything in real world. It allows us to think about everything in the universe as an object so we can easily work with them. In this Java programming tutorial, we will learn basic pillars of Object Oriented Programming.
Object Oriented Programming has 4 pillars:
“Eliminate the Irrelevant, Amplify the Essential”
Abstraction is to focus on the essential and discard the irrelevant. In a way this does not make sense unless you have a scope. Example in the image above the vet is a doctor of animals her view of the cat that is important to her would be the parts of the cat while thing like the cat favorite toy might not be of relevance to her. Whereas for the owner of the cat her view of the cat is different from the Vet.
“Hiding the Unnecessary”
Encapsulation is hiding the unnecessary. Meaning things that you do not want other people/classes to know are to be hidden. For example in the image the professor do not need to know how a student does her assignment. He is more interested in the end product.
In a way encapsulation protect the system, since it hides stuff that can be vulnerable to malicious attack. There are also many other drawbacks to create a system without encapsulation. You can find it out in our book chapter.
“Modeling the Similarity”
Similarities often exist in the world. As shown in image above, one could easily see that there are some similarities between the two President of United States, George H.W Bush (41st President) and George W. Bush (43rd President).
George W. Bush is a son of George H.W Bush. He inherits biological features from his father, at the same time, has his own unique feature that one could identify him as George W. Bush. This bring us to the idea of inheritance that models a “is a” relationship between objects.
“Same Function different behavior”