Object-Oriented Programming - 4 Main Principles
|
Encapsulation |
is achieved when an object keeps its state ENCLOSED from other objects (via private instance fields) |
|---|---|
|
Abstraction |
is achieved when an object only EXPOSES a high-level mechanism for using it (via public methods) |
|
Inheritance |
is achieved when an object (child-class) REUSES/OVERRIDES the state and/or code of another object (parent-class) |
|
Polymorphism |
is achieved when an object (child-class) can be used EXACTLY like its parent (a less strict version of Liskov Substitution Principle) |
Object-Oriented Programming - Additional Principles
- All pre-defined types must be objects
- All user-defined types must be objects
- All operations on objects must be done through methods
Object-Oriented Programming - Essentials & Non-Essentials (according to Alan Kay)
Essentials:
- Encapsulation
- Message passing
- Dynamic binding (the ability for the program to evolve/adapt at runtime)
Non-Essentials:
- Classes
- Class inheritance
- Special treatment for objects/functions/data
- The new keyword
- Polymorphism
- Static types
- Recognizing a class as a “type”