Sign in to follow this  
hymerman

Intercepting commands in the Command pattern

Recommended Posts

Hi all, I'm changing an existing message-based system to use the Command pattern. The application is a music player. I'm getting to the point where messages aren't enough; I need to pass data with them ('play X', 'add {X} to playlist'), and I'd like undo functionality and so on. The Command pattern seems ideal, but I'm unsure of how to implement a feature that's quite easy using messages. An example: Previously, there were two things listening for the 'Play' message - the Player, which starts playing when it receives the message, and the PlaybackQueue, which empties its queue. The playback queue doesn't necessarily exist - it is implemented as a plug-in. Since commands would be bound to a particular service ('PlayCommand'), and would do one thing (tell the player to start playing), I'm unsure of how I'd go about doing this - I can't just dynamically add behaviour to the class since this is C++, and I can't 'listen' for commands since they choose what they act upon, rather than being broadcast as messages were. Can anyone point me in the right direction? Thanks in advance!

Share this post


Link to post
Share on other sites
Why not mix the two? Having a Play command, and then an OnPlay, OnPlayUndo message/event. The command for the user visible interface and the message for internal/plugin hooks. Granted, that'll make it pretty difficult to present plugin dependent stuff to the user.... hrm.

Share this post


Link to post
Share on other sites
Quote:
Original post by Vorpy
What would undoing pressing the play button actually do?


Um...stop...? Good point, perhaps only certain commands will be undo-able.

Telastyn, good point, I could ping off a message when commands are executed. This may prove inefficient, in that there's be more stuff going on than there was before, but... we'll see. Thanks for that!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this