Programming languages that are object-oriented are considered to have powerful features above and beyond other, merely mortal languages. Moreover, the style in which developers must think when working with object-oriented languages differs from that of more traditional procedural languages like Pascal and C.
There's some debate about just exactly what features are required to make a language object-oriented. From a practical point of view though, these four features are probably enough to draw a Yes vote from most people:
- Encapsulation Â data and operations on that data can be grouped together in a single entity: an object.
- Aggregation or containment Â objects can have other objects inside them.
- Inheritance between object types Â the nature of an object can depend on more than one definition.
- Polymorphism or late binding Â the user doesn't always have to know the exact nature of an object in order to use one of its features. The system can figure out what is meant automatically.
- Association: objects can refer to other objects.
- Encapsulation: yes Â but no information hiding.
- Aggregation or containment: yes Â but no information hiding.
- Inheritance: yes Â but inheritance concepts are different for a fully interpreted language.
- Polymorphism or late binding: yes Â fundamental to the language.
- Association: yes Â fundamental to the language.
It's pretty obvious that all the script does is to create two effectively identical objects. They both have the same properties and the same values associated with those properties. So what we can see from here is that ignoring how they got those properties, both objects group the two together under one umbrella which we can refer to Â they encapsulate the properties.
In this example, object1 is probably created in a more "object-like" manner since we bother to define all the features of the object in one place (in the constructor function Square()) before we make the object up. Functionally there is little difference.
Created: February 5, 2001
Revised: February 5, 2001