oop - Why do we need a "receiver" class in the Command design pattern -


i learning command design pattern. far know, 4 terms associated command pattern command, receiver, invoker , client.

a concrete command class has execute() method , invoker has couple of commands. invoker decides when call execute() method of command.

when execute() method called, calls method of receiver. then, receiver work.

i don't understand why need receiver class? can work inside execute() method, seems receiver class redundant.

thank in advance.

design patterns used solve software problems.

you have understand problem before trying understand solution (in case command pattern)

the problems command pattern apply in context of object (client) invoking method in object b (receiver), receiver part of problem, not part of solution.

the solution or idea command pattern offers encapsulate method invocation b in object (command), in fact close formal pattern definition. when manage request object able solve problems or implement features. (you need other pieces 1 called invoker)

this list can give examples of kind of problems o features suitable command pattern.

note: comamnd pattern not necesary decoupling, in fact common example pattern immplementation, client needs make new instance of receiver cannot talk decoupling here.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -