Object-oriented basics: inheritance, polymorphism, encapsulation, and abstraction
Inheritance
- prototypal inheritance allows an object
- to base itself on another object
- class-based inheritance allows a class
- to base itself on another class
- both allow the child to access
- the parent's capabilities
- note: inheritance != subtyping
- though often inheritance agrees with subtyping
Polymorphism
- allows a routine (function, method, constructor...)
- to use variables of different types
- at different times
-
there are three kinds of polymorphism
- ad hoc polymorphism
- parameteric polymorphism
- subtype polymorphism
Encapsulation
- allows an object (or a closure)
- to restrict outside access
- to some of its components
- and to bundle data with the routines
- that operate on that data
Abstraction (in an OO context)
- allows us to define objects which can...
- perform work,
- report on and change their state, and
- communicate with other objects
Abstraction enables encapsulation, polymorphism, and inheritance.