Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNorman Barrows

Posted 11 September 2013 - 02:00 PM

didn't look at the code too closely, and from the comments it wasn't really necessary, but....

 

in plain engish, in the strategy pattern, you call a function, and pass it a flag somehow (explicitly or implicitly  - such as "this"), and it in turn calls some sub-function based on that flag.  an example might be some move method that used object type to in turn call a move_ground_target or move_flying_target method.

 

the idea is that you can use one api call move(this) to call different move() methods based on "this", to implement different "flight models".

 

its a common way to generalize and reduce the number of API calls when designing an API.

 

for example, in my game library, i have drawing down to one call: Zdraw(drawinfo) that works for mesh&texture, static model, animated model, 2d billboard, or 3d billboard   (   hey! i should add sprites! <g>   ).   all it does is a switch on drawinfo.type and calls the appropriate sub-function based on type. its a perfect example of the strategy or policy pattern.  drawinfo.type is the strategy or policy to be used when drawing.


#2Norman Barrows

Posted 11 September 2013 - 01:59 PM

didn't look at the code too closely, and from the comments it wasn't really necessary, but....

 

in plain engish, in the strategy pattern, you call a function, and pass it a flag somehow (explicitly or implicitly  - such as "this"), and it in turn calls some sub-function based on that flag.  an example might be some move method that used object type to in turn call a move_ground_target or move_flying_target method.

 

the idea is that you can use one api call move(this) to call different move() methods based on "this", to implement different "flight models".

 

its a common way to generalize and reduce the number of API calls when designing an API.

 

for example, in my game library, i have drawing down to once call: Zdraw(drawinfo) that works for mesh/texture, static model, animated model, 2d billboard, or 3d billboard - hey! i should add sprites! <g>.   all it does is a switch on drawinfo.type and calls the appropriate sub-function based on type. its a perfect example of the strategy or policy pattern.  drawinfo.type is the strategy or policy to be used when drawing.


#1Norman Barrows

Posted 11 September 2013 - 01:57 PM

didn't look at the code too closely, and from the comments it wasn't really necessary, but....

 

in plain engish, in the strategy pattern, you call a function, and pass it a flag somehow (explicitly or implicitly  - such as "this"), and it in turn calls some sub-function based on that flag.  an example might be some move method that used object type to in turn call a move_ground_target or move_flying_target method.

 

the idea is that you can use one api call move(this) to call different move() methods based on "this", to implement different "flight models".

 

its a common way to generalize and reduce the number of API calls when designing an API.

 

for example, in my game library, i have drawing down to once call: Zdraw(drawinfo) that works for mesh/texture, static model, animated model, 2d billboard, or 3d billboard - hey! i should add sprites! <g>.   all it does is a switch on drawinfo.type and calls the appropriate sub-function based on type. it a a perfect example of the strategy or policy pattern.  drawinfo.type is the strategy or policy to be used when drawing.


PARTNERS