Note that there are some explanatory texts on larger screens.

plurals
  1. POModel the real world or the proper OOP world? Or both?
    text
    copied!<p>I'm writing a game where the mouse-driven controller object clicks on a player object to have it do something.</p> <p>There are 2 ways of initiating the interaction between mouse and player: </p> <ul> <li><strong>Controller calls player's function:</strong><br> Controller listens for mouse events. When a mouse click occurs anywhere onscreen, the controller searches all objects under the point that was clicked. If one of the objects is a player object, and it's "clickable" property is true, then call its appropriate function.</li> <li><strong>Player calls controller's function:</strong><br> Player listens for mouse events. When a mouse click occurs on the player, and the player's own "clickable" property is true, then call the controller's appropriate function.</li> </ul> <p>My dilemma here is that the first option seems more intuitive with how I imagine the scenario happening in the real world, but the second option seems more intuitive with proper object-oriented design because it doesn't require looking into another object's property, which violates encapsulation to some extent (the controller must look into the player to read its "clickable" property). Also, the second option seems inline with the 'Controller' design pattern.</p> <p>This is always a struggle for me -- do I defy proper object-oriented design (e.g. option 1) or do I use an implementation that seems counterintuitive to the real world (e.g. option 2)?</p> <p>I'm hoping there's some kind of middle ground I'm missing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload