Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am planning to create an application to create software mockups. It will have some different elements but with similar behavior (like windows, buttons, menubars, etc), so I am planning to use the Component-pattern to make it easier to create and control these elements' behavior. For example I could create a "GenericComponent" to control actions over basic components like buttons or images and another Component to control elements with multiple children like windows or thumbnails.

As far as I read on internet I only found Component-pattern implementations where its call must have a fix number of parameters or a fix number of functions available for each component (like Create(),Destroy(), Update() for game components). So I tried to implement a generic component implementation. With this one I think that I am able to create any number of functions per component, it is easy to call them and the number of parameters for each function can change too. Also the component can have any number of internal parameters to help with the function processing.

TL;DR: Here is a link with an example of the component-pattern implementation that I did, what do you think? Is it efficient? Useless? Do you have a better suggestion? Thanks for the attention

Here is the generic-component implementation, there is an example of its use on the following jsfiddle link:

function Component( baseObject )
{
    this.base = baseObject;
    this.funcArray = new Array();
}

Component.prototype.constructor = Component;

Component.prototype.addFunction = function ( funcKey, funcImp )
{
        this.funcArray[ funcKey ] = funcImp;
}

Component.prototype.callFunction = function( funcKey, funcParams )
{
    this.funcArray[funcKey].apply( this.base, funcParams );
} 

http://jsfiddle.net/Kaze_Senshi/Zb89h/

share|improve this question

migrated from stackoverflow.com Feb 27 at 9:41

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.