Mastering JavaScript Object-Oriented Programming
上QQ阅读APP看书,第一时间看更新

OOP principles

OOP is one of the most popular programming paradigms. Many developers use languages based on this programming model such as C++, Java, C#, Smalltalk, Objective-C, and many other. One of the keys to the success of this programming approach is that it promotes a modular design and code reuse—two important features when developing complex software.

However, the OOP paradigm is not based on a formal standard specification. There is not a technical document that defines what OOP is and what it is not. The OOP definition is mainly based on common sense taken from the papers published by early researchers as Kristen Nygaard, Alan Kays, William Cook, and others.

Note

An interesting discussion about various attempts to define OOP can be found online at the following URL:http://c2.com/cgi/wiki?DefinitionsForOo

Anyway, a widely accepted definition to classify a programming language such as Object Oriented is based on two requirements-its capability to model a problem through objects and its support of a few principles that grant modularity and code reuse.

In order to satisfy the first requirement, a language must enable a developer to describe the reality using objects and to define relationships among objects such as the following:

  • Association: This is the object's capability to refer another independent object
  • Aggregation: This is the object's capability to embed one or more independent objects
  • Composition: This is the object's capability to embed one or more dependent objects

Commonly, the second requirement is satisfied if a language supports the following principles:

  • Encapsulation: This is the capability to concentrate into a single entity data and code that manipulates it, hiding its internal details
  • Inheritance: This is the mechanism by which an object acquires some or all features from one or more other objects
  • Polymorphism: This is the capability to process objects differently based on their data type or structure

Meeting these requirements is what usually allows us to classify a language as Object Oriented.