Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Really, you're asking about the <strong>Factory</strong> pattern or a <strong>dependency injection</strong> container such as Spring.</p> <p>Of course you can call the methods on an interface, the question is <strong>how you get the instance</strong>. That of course has to be specified, coded or configured somewhere. Configuration is preferable if there could ever be more than one in the future.</p> <p>Thus, more of a real example:</p> <pre><code>public interface MovementStrategy { public Move selectMove (Actor actor, ActorSituation theirSituation); } public class MonsterTypes { public static MonsterType GOBLIN = new MonsterType( "goblin", new AttackMover(1.2)); public static MonsterType TROLL = new MonsterType( "troll", new AttackMover(0.45)); public static MonsterType DEER = new MonsterType( "deer", new FleeMover(2.0)); // useful to have, also. public static List&lt;MonsterType&gt; getAllRegisteredTypes(); public static class MonsterType { protected String name; protected MovementStrategy moveStrategy; // TODO -- getters &amp; setters for all properties. // constructor. public MonsterType (String name, MovementStrategy moveStrategy) { this.name = name; this.moveStrategy = moveStrategy; } } } public class AttackMover implements MovementStrategy { // SPEC: generally move towards/attack PC, with varying speeds. } public class FleeMover implements MovementStrategy { // SPEC: generally run away from PCs. } </code></pre> <p>This isn't probably a perfect design -- it conflates "movement" (aka goal-seeking) with the actor's turn/actions overall -- but hopefully it gives you some more idea.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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