Skip to content
fladdict edited this page Aug 27, 2012 · 21 revisions

What is AAMCommandKit?

AAMCommandKit is command pattern library for objective-c.
Document Writer needed! I'm not a primally English speaker, need some's help for good documentation.

Sample Code

Using multiple command as batch.

Simply alloc and call execute.

AAMLogCommand *command = [AAMLogCommand commandWithString:@"Hello World"];
[command execute];  //prints "Hello World"

Using multiple command as batch.

By using AAMSerialCommand or AAMParallelCommand, you can sequentially execute multiple command.

NSMutableArray *ar = [NSMutableArray arrayWithCapacity:5];
[ar addObject:[AAMLogCommand commandWithString:@"First Command"]];
[ar addObject:[AAMLogCommand commandWithString:@"Second Command"]];
[ar addObject:[AAMLogCommand commandWithString:@"Third Command"]];

AAMSerialCommand *command = [AAMSerialCommand commandWithCommands:ar];
[command execute];

Using selector as Command.

You can use selector with AAMSelectorCommand.

AAMSelectorCommand *command = [AAMSelectorCommand commandWithTarget:self selector:@selector(mySelector)];  
[command execute];

Using block as Command.

You can use block with AAMBlockCommand.

AAMBlockCommand *command = [AAMBlockCommand commandWithBlock:^(void){ doSomething }];  
[command execute];

Event handling

You can use both delegate and Notification for event handling.

AAMLogCommand *c = [AAMLogComamnd commandWithString:@"do something"];
c.delegate = self;
[c execute];

How to write your own Command.

Extend AAMCommand

Override _setupCommand;

If your commands needs some setup. Write it here. _setupCommand is executed in the beginning of command execution.

Override _executeCommand;

write your own processing hrere.

-(void)_executeCommand{ // }

Call _dispatchComplete

When you finished all your processing call one of following method.

Generally you use _dispatchComplete.

  • [self _dispatchComplete];
  • [self _dispatchCancel];
  • [self _dispatchStopWithError:(NSError*)theError];

Override _teardownCommand;

If your commands needs to release object. Do it here. _teardownCommand is executed at the end of command execution.