give me a

Presentation by Vladimir Minkin

GOF

SAID

Encapsulate a request as an object, thereby letting users parameterize clients with different requests, queue or log requests, and support undoable operations.

GOF

SCHEMA

- Client

- Invoker

- Receiver

- ICommand

- ConcreteCommand
  • Client
    - creates a ConcreteCommand object and sets its receiver
    - act as a Controller and ask Invoker to fulfill the request
     
  • Invoker
    - Holds commands and "asks" it to carry out the request
     
  • Receiver 
    - knows how to perform the operations associated with carrying out the request.
     
  • ICommand
    - declares an interface for executing an operation
     
  • ConcreteCommand
    - defines a binding between a Receiver object and an action
    - implements Execute by invoking the corresponding operation(s) on Receiver
Invoker (CommandCollector)
ConnectToOracleServerCommand (IServerCommand)
ServerProxy (Receiver)
- checkNetwork
- createConnection
- storeConnection
- informClientWithStatus
.execute()
ApplicationProxy (Receiver)
- getAccessToken
- getCachedData
- updateConnectionType
- doSomethingOnThread
SaveImageContentCommand (IContentCommand)

private Object State

CONTROLLER (Client)
GUI
GUI
GUI
GUI
View

IDEA

- Encapsulate processing to an Object 

- Easy functionality replacement

- Combining actions

- State holder

- Delay calls
 

A command
is a extracted
method call.

It’s a method call wrapped in an object.

an object  that you can stick in a variable, pass to a function, etc.


closure
callback
function pointer

first-class function

partially applied function

Direct execution 
to hide unnecessary code.
Command can return value, 
even Promise.
- be stored with key for later use (Observer)
- execute another commands (Macros)
- do business logic and act as a brain
- hold and modify state or data
- be sequenced (Async)

Commands

can

I SEE FIRE

Benefits

- Loose coupling
- No duplication
- Reusable code
- Better Tests

EXAMPLES

COMMAN

Global object that act as Callback holder and Invoker, 
but return Promise

PureMVC

by Mr. Cliff Hall

I know kung fu.
Show me.

THANK YOU!

Vladimir Minkin
Software-Design 
#docoderight

 

email: vladimir.minkin@gmail.com

Give me a Command

By Vladimir Cores Minkin

Give me a Command

Story about Command Pattern

  • 775