It sounds like you might want some "default arguments". In Python, you could do something like this:
class MyClass:
def __init__(done=false, load=1, ...):
self.done = done
self.load = load
# ...
a_new_instance = MyClass(done=true)
Basically, all of your variables start out with a default value - but you can change them if you are so inclined.
In Java, it is a little different:
class MyClass {
private boolean done = false; // Notice the default value for done will be false
// ... you would list (and instantiate!) the rest of your variables
public MyClass() {}
public MyClass(boolean done, int lvl, ...) {
this.done = done;
// ...
}
}
In this way, you are only forced to call the constructor if you want to change the default values. But what happens if you only want to change 1 or 2 values? Well, you could make new constructors:
public MyClass(boolean done) { this.done = done; }
public MyClass(boolean done, int lvl) { this.done = done; this.lvl = lvl; }
but this will quickly get out of hand!
So, to get around this, we can use a "builder" pattern. That will look something like this:
public class MyClass {
private boolean done;
private int lvl;
// Now the constructor is private and takes a builder.
private MyClass(MyClassBuilder builder) {
// ... and your variables come from the ones you will build.
this.done = builder.done;
this.lvl = builder.lvl;
// ...
}
public static class MyClassBuilder {
// The builder also has the same members.
private boolean done;
private int lvl;
// Notice that we return the builder, this allows us to chain calls.
public MyClassBuilder done(boolean isDone) {
this.done = isDone;
return this;
}
public MyClassBuilder level(int level) {
this.lvl = level;
}
// And a method to build the object.
public MyClass build() {
MyClass mc = new MyClass();
mc.done = this.done;
mc.lvl = this.lvl;
// ... copy over all your variables from the builder to the new class
return mc;
}
}
}
So, now when we want to instantiate a MyClass
object we can do this:
MyClass mc = MyClassBuilder.done(false);
or, we can chain the calls:
MyClass mc2 = MyClassBuilder.done(true).level(4). // ... you can go on for a while
As an aside, sometimes having more than three or four variables in a class is a sign that the class is doing too much. If the class has more than one "responsibility", you should break it up into a few smaller classes. Then you won't need a builder class.