ChiaFong

Posts Tagged ‘Object Oriented’

More OO?

In Programming on 12 July, 2006 at 3:48 pm

Can a language be more object-oriented (OO) than another language?  OO is a programming paradigm, a style of programming.  This style of programming emphasizes the following concepts:

  • Class – a unit definition of something that belong in a set, Dogs can be considered as a class.
  • Object – an instance of a class, a runtime manifestation of a class.  My wife’s favourite dog, Zombie, would be an instance for the class Dogs.
  • Method – way to interact with an object of some class.  Dogs can contain a method call ActCute, so to ask Zombie to act cute, you can use this method.
  • Inheritance – way to define a class as having all attributes of another class, this kind of class thus defined would normally be call a subclass.  Pomeranian can be a subclass of Dogs.  Zombie will then be more correctly instantiated as Pomeranian, as it is of that kind of breed.
  • Encapsulation – way of hiding the implementation detail of an object.  You can ask Zombie to ActCute but you won’t know its do that.
  • Abstraction – way to ignore details of an object’s subclass and work at a more generic level.  Zombie can be considered as a Pomeranian most of the time, but when needed it can be abstracted as a Dog.
  • Polymorphism – a way whereby an object can dynamically change its behaviour during runtime.  If you think of Zombie as a Dog then it should be able to guard the house, but if you then know that Zombie is actually a Pomeranian, you would know that Zombie is more for play.

A language can be consider OO, as long as it provide mechanisms to support most of the above concepts, so that OO developers can program at ease.  However, certain language might choose not to support certain concept and thus can be consider “less OO”.  For example, Visual Basic does not support inheritance and Java does not support multiple-inheritance which is a more complex mechanism of inheritance.