How to design app to be modular / support plugins

Posted by Lee on Stack Overflow See other posts from Stack Overflow or by Lee
Published on 2010-05-07T13:25:19Z Indexed on 2010/05/07 13:28 UTC
Read the original article Hit count: 216

Filed under:
|
|
|
|

I'm currently in the process of refactoring my webplayer so that we'll be more easily able to run it on our other internet radio stations. Much of the setup between these players will be very similar, however, some will need to have different UI plugins / other plugins.

Currently in the webplayer I do something like this in it's init():

_this.ui = new UI();

_this.ui.playlist = new Playlist();

_this.ui.channelDropdown = new ChannelDropdown();

_this.ui.timecode = ne Timecode();

etc etc

This works fine but that blocks me into requiring those objects at run time. What I'd like to do is be able to add those based on the stations needs. Basically my question is, do I need to add some kind of "addPlugin()" functionality here? And if I do that, do I need to constantly check from my WebPlayer object if that plugin exists before it attempts to use it? Like...

if (_hasPlugin('playlist')) this.plugins.playlist.add(track);

I apologize if some of this might not be clear... really trying to get my head wrapped around all of this. I feel I'm closer but I'm still stuck. Any advice on how I should proceed with this would be greatly appreciated.

Thanks in advance,

Lee

© Stack Overflow or respective owner

Related posts about oop

Related posts about JavaScript