Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement strategy pattern in a controller
    primarykey
    data
    text
    <p>I am trying to implement a strategy pattern for the controller component of my program. </p> <p>I have different view states such as CreateViewState in which you can create items on a blank canvas, so it needs methods like, <code>createInput()</code>, <code>addToModel()</code> and <code>stuff</code>.</p> <p>Another state that I have is the EditViewState in which you can edit the previously added items. You select an input and then change its color or size or whatever. So methods that controller needs is <code>selectInputAtLocation()</code>, or <code>changeColor(java.awt.Color color)</code> or <code>changeSize(int size)</code>...</p> <p>The way I go about it is I created an IController interface that has common methods like repOK(), toString() and a couple more like thisWasTheLocation(int x, int y) which the view calls statically to pass the location pressed on the screen to the controller.</p> <p>However for doing their specific job I don't have a common method that they have. I was thinking about putting a <code>doStuff(Item item)</code> method in the interface and then do the controller logic in there so client code can use <code>IController.getInstance().doStuff(item)</code> in the entire code. As far as I can predict I will need to cast the controller if I call the specific methods that they have (<code>changeColor()</code> for editController, <code>createInput()</code> for createController).</p> <p>If I create a <code>doStuff()</code> method in the interface, then I need to implement a lot of if-statements especially for the editController (it has more than 7-8 methods that I did not mention).</p> <p>How should go about designing this whole system?</p> <p>P.S: <code>Controllers</code> are singletons therefore the <code>getInstance()</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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