Encapsulation is the ability to hide the internal workings of an object's behavior and its data. For instance, let's say you have a object named
Car
and this object has a method (another word for behavior) named start()
. When you create an instance of a car object and call its start()
method you are not worried about what happens to accomplish this, you just want to make sure the state of the car is changed to 'running' afterwards. This kind of behavior hiding is encapsulation and it makes programming much easier. When you want your car object to be in a 'running' state, instead of calling: fuel.on()
, starter.on()
, etc., you just call start()
. This not only makes it easier to work with, but if the internal workings of this start() method have to change, the results will be the same.What is Polymorphism?
Polymorphism as the name suggests is the ability of the object to be treated differently based on the data types and classes
It is provided in two fashion of Static and Dynamic Binding
Definition (Static Binding) If the type T of a variable is explicitly associated with its name N by declaration, we say, that N is statically bound to T. The association process is called static binding.
Definition (Dynamic Binding) If the type T of a variable with name N is implicitly associated by its content, we say, that N is dynamically bound to T. The association process is called dynamic binding.
No comments:
Post a Comment