Wednesday, October 08, 2008

Component Oriented Programming

The difference between component oriented programming and object oriented programming is focus. In object oriented programming the focus is the objects themselves which is why you access methods through objects like this:

CoreObject * object = new CoreObject;

object->rename("My Object");

In component oriented programming the focus is the components and objects are just placeholders for instances like this:

CoreObject * object = CoreObjectNew();

CoreObjectRename(object, "My Object");

It looks like procedural programming but the difference is that it uses objects. One of the reasons object oriented programming has never able to become a file system is because when objects are created, they are stuck in stone in their definition. While their properties can be modified, you cannot add/remove properties. In component oriented programming, an object is just a placeholder where you attach/detach components to objects. Each component has a data definition associated with it. Because of this, when you attach an object to a component, you attach private data of the component to the object. Each component only accesses its private data per object and does not read or write another component data directly but rather uses the API provided by the other components.

That is component oriented programming in a nutshell.

1 comment:

Anonymous said...

So now call it component-based programming instead.

Still object-oriented.

Yours is component-based object-oriented programming as opposed to the OO-programming familiar to most people, which is class-based.

You could consider modifying the blog description too, to add "component-based" before "object-oriented".