0

I have an abstract class to be used as a template for my programs. This abstract class has a constructor that currently accepts 7 booleans, each defining whether or not a certain module will be used and should be enabled (constructed). Instead of passing 7 booleans to this super constructor, I thought about passing a list of strings or a string of characters that match up to a module to enable. This seems like a bad workaround for what I want since it requires memorizing the module codes (They would be in the javadocs, but is still not my preference). My next thought is to use annotations for each module you want to enable. Each module would have an annotation associated with it, and the super constructor would read the subclasses annotations to determine what to enable. Is there any proper or elegant way to do this module system? I feel like all of these systems are not optimal.

Super class:

public Template(boolean commands, boolean config, boolean listeners, boolean logging, boolean permissions, boolean reflection, boolean threads) {
    this.commandManager = commands ? new CommandManager(this) : null;
    this.configManager = config ? new ConfigManager(this) : null;
    /*...*/
}

public CommandManager getCommandManager() {
    return this.commandManager;
}

Subclass that uses commands and permissions (alternate calls shown in comments)

public SubTemplate() {
    super(true, false, false, false, true, false, false);
    //super({"commands", "permissions"});
    //super("Cp"); C being commands, p being permissions
}
CrypticStorm
  • 560
  • 2
  • 11
  • I think you should review your general structure. A constructor with 7 booleans or strings etc. is not readable and you can make very very many swap mistakes. Another point is that you shouldnt get "this" some other object in the constructor, because the other object could get an incomplete state of the Template object. – pL4Gu33 May 01 '14 at 15:56
  • Your design sounds extremely flawed. Sounds like your template is too abstract. Consider having more templates which extend the base template. Alternatively, consider a frame work like spring which injects the required components. – TedTrippin May 01 '14 at 15:58
  • The 7 booleans and strings is the exact reason why I think there is a problem. The superclass is used to hide the CommandManager constructors which are safe and merely store a reference to the Template. The class is also final. – CrypticStorm May 01 '14 at 15:59

0 Answers0