Android Example Duck Typing and Command Design Pattern Example

I hope I have got this example right. Any positive criticism or improvements will be welcome!
I have made this to try learn and understand how this all works. This could also help others to understand.

My example shows a different example of Duck Typing (an alternative to using squares, circles and lists as in the Class example of Erel's) as well as a basic Command Pattern.

Some uses of the Command Pattern are:
  • Menu's - that can be shuffled around dynamically - the Duck Typing will "find" the right one.
  • Queuing requests - i.e. list of jobs: once one is completed select the next in the queue.
  • Macro Commands.
  • Logging requests.

Command Pattern Definition:
The Command Pattern encapsulates a request as an object, thereby letting one parametise
other objects with different requests, queue or log requests, and support undoable operations


The attached program in layman's terms:
The user interface is a remote control for an automated house
The user clicks any button on the remote and sends an encapsulated message.
The Command Object doesn't care what it is or where it goes - it is just an object.
The Receiver (Class) waits for an action to be invoked upon it.
 

Attachments

  • DuckTypingCommandPattern.zip
    10.2 KB · Views: 418
Top