So what the OOP is all about? Inheritance is only the small piece.
The three main features should be supported:
- It is possible to create a child object
TreeMenuwhich extends functionality of the
The child object automatically gains access to parent’s methods/properties, but it also can have own methods/properties.
That’s great, because allows to reuse generic
SlidingMenuand other specific menu types.
- An object can forbid external access to chosen properties and methods, so that they can only be called by other methods of same object.
That allows to hide internal details of
For example, the code which uses a
Menushould not directly access it’s DOM structure, handler etc. They are internal.
On the other hand, there should be
hideand other publicly accessible methods. These methods are called an external(or public) interface.
There are three most well-known encapsulation levels:
- Accessible only from the class itself, not accessible from inheritants.
- Accessible from the class itself, inheritants are also allowed to access it.
- Accessible from anywhere.
Encapsulation helps to support the code, because a programmer always knows, which methods could have been used by the external code, and which can be safely modified or even removed.
- Type polymorphism
- A code which uses the
Menuobject can switch to a
TreeMenuobject or a
It’s possible, because the public interface of