validation - Where should I validate arguments? Factory Pattern, Java -


suppose have abstract class abstract builder, both of inherited 3 separate subclasses:

public abstract class role {      protected string name;     protected int propertya;     protected int propertyb;       protected abstract static class rolebuilder<t extends role, b extends rolebuilder<t,b>> {           protected t role;         protected b rolebuilder;          protected abstract t getrole();         protected abstract b thisbuilder();          protected rolebuilder(hero h) {              role = getrole();             rolebuilder = thisbuilder();              role.name = h.name;             role.propertya = h.propertya;              role.propertyb = h.propertyb;          }          public t build() {             return role;         }      } }   public class healer extends role {      int propertyc;      public healer() {      }      public static final class healerbuilder extends role.rolebuilder<healer, healerbuilder> {          @override protected healer getrole() {             return new healer();         }          @override protected healerbuilder thisbuilder() {             return this;         }          public healerbuilder(hero h) {             super(h);         }          public healerbuilder setpropertyc(int i) {             role.propertyc = i;             return rolebuilder;         }       } } 

i instantiate healer class (and other 2 subclasses) using enums methods within enums, so:

public enum roletypes {     bruiser{     ...     },     damage_dealer {     ...     },     healer {          public healer getrole(hero h) {             return new healer.healerbuilder(h)                      .setpropertyc(h.getc);                     .build();         }      };      abstract role getrole(hero h); } 

where should validating arguments creation of these objects?

  • within abstract class constructor (should validate hero object properties, or can assume object "safe" if properties validated on creation?) , subclass builder methods?

  • within enum methods?

  • within factory method calls roletype.getrole(h), used rest of application create objects of type role?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -