+ 2
Object Oriented, Whats this again?
Wat, Read the title again
2 ответов
+ 5
In OOP, the whole functionality of the program revolve around objects.
Objects are nothing but instances of a class.
You can think of a class as a blueprint.
When you create an object you use that blueprint for processing your specific data values.
+ 1
And the fundamental principles of OOP are Abstraction, Encapsulation, Inheritance and Polymorphism.
In short..
Abstraction is about how we can abstractly describe real world objects in our programs.
Encapsulation means hiding object's inner data or implementation complexity. It can look like a "black box", so you do not need to know what exactly is happening inside the box, but you have some external mechanisms (methods) which you can use to change it's state or tell the object to do some functionality. Encapsulation also helps to maintain object's consistency and security.
Inheritance is a powerful mechanism in OOP which helps to reuse code and extend behaviours of classes. One of the other benefits of it is classes hierarchy.
Polymorphism is a concept of using different types of objects to do some functionality.. or to have some functions or methods to act differently according to the actual types of parameters...
for example, we can place markers at some POIs on google maps and we are able to use different types of markers, markers of different color and shapes.. and we can use the power of polymorphism to have a List<Marker> (collection of markers) where Marker is the base class and we can put in the List GreenMarker, RedMarker, AnimatedMarker, and so on.. which are subclasses of Marker.... Having that list we can pass it to a method which will draw them on a layer and they will be drawn according to their actual types.. Polymorphism can be achieved through inheritance (subclassing), methods overriding, overloading, interfaces and abstract classes...