Java Command Pattern vs iPhone Delegate Template

Hi I am a Java developer, and these days I also started working on developing iphone. I was wondering if the Java command template is somewhat similar to the delegation template in iphone or vice versa, because there is someone else in it doing the work for the assignee. Can someone enlighten me on this?

+4
source share
1 answer
Strictly speaking, they are different, although they complement each other.

Command pattern is an encapsulation of an operation / request / action as an object. Although the common reason for encapsulating an operation as an object would be to send it to the delegate, there are many other reasons why you can use the command template, for example. to create a cancellation mechanism or to record an audit trail.

Delegate pattern is one shadow of an object after another to support it. Usually this ratio is 1 to 1. On an iPhone, a window may have a window delegate. A window may ask the Window delegate how to respond to specific user actions. If different user actions were autonomous objects, then they can be an example of a command template, but this is a separate idea from the Window delegate.

From what I understand (which, however, is very small), the delegation in the Cocoa model does not use command objects between the delegate and the delegate (although the method call is sometimes called a "message" on OO speak as if it were a real entity).

The two ideas are complementary and often used together, but they are separate ideas. You can use the team template without delegates and delegates without team objects.


Cm:

http://en.wikipedia.org/wiki/Command_pattern

http://en.wikipedia.org/wiki/Delegation_pattern

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW18

+6
source

Source: https://habr.com/ru/post/1333135/


All Articles