Design Patterns: Command Pattern - TeamCrazyPerformance/Game_study GitHub Wiki

Command Pattern

Command Pattern

  • Encapsulate a request as an object
    • A Command is a reified method call - (thingify ), method call wrapped in an object command
  • sounds similar like callback, first-class function, function pointer, colsure or partially applied function
  • commands are an object-oriented replacement for callbacks

Configuring Input

image

  • It is hard wired - but many games let user configure it — to do it, wee need to turn those direct calls (jump fireGun …) into something that we can swap out - so we need an object that we can use to represent a game action → command pattern

image

Untitled

Untitled

Directions for Actors

  • but it doesn’t give direction - we dont want to couple the player character. to solve this issue, we will pass in the object that we want to order around:

    Untitled

    Untitled

Untitled

Untitled

  • Not only user, these can be used to AIs in the games,

Encapsulate a request as an object, letting users parameterize client with dirrerent requests, queue or log requests, and support undoable operations….(Gang of Four)

A Command is a reified method call - (thingify ), method call wrapped in an object

Command - 객체화된 매서드 콜