Monday, April 19, 2010

Component-based or object-oriented?

Since I'm using Unity, whose scripting uses the component paradigm, my implementations use components too. However I get into this situation where a particular collection of components are similar with each other, their source code literally the same with each other save for a few key areas, those key areas giving them distinction from each other.

For example I have a base attack skill, and then I have another, similar attack skill except that it has a cooldown effect. The two are virtually the same except the latter has added code for handling cooldown effect.

In object-oriented programming, I would create a subclass of the attack skill as something like AttackSkillWithCooldown and override the member functions needed to add the cooldown effect.

In component-based programming, I would create cooldown as a separate component to be attached to the attack skill component.

So on one hand I have object-oriented programming which I'm used to and know how to implement, and on one hand I have component-based programming, which looks like more work upfront. I'm still not sure how to implement things in component-based programming but I can't help but think it may be worth it in the long run.

3 comments:

  1. may alam kabang magandang video or tutorial na mag eexplain about sa OOP usage specifically sa Unity?

    component-based kasi ung project na ginagawa ko, mejo ang hirap na i-organize ung mga script :(

    ReplyDelete
  2. Kung javascript gamit mo, ito ang tumulong sakin kung pano gumawa ng classes: http://www.unifycommunity.com/wiki/index.php?title=Head_First_into_Unity_with_JavaScript#Subclassing_is_Less_Annoying_than_Real_JavaScript

    ReplyDelete

Made me post. 0/10.