Good way to practice a class of children

advertisements

So I have about 10-15 classes (this could grow to a much larger number in time) and they all have fairly similar variables within them:

temp
conditions
humidity
load

..And stuff like that. I'm looking to implement a parent class (abstract) to better manage this since they are all runnable.

There's a part where I call a constructor for each of them and it's... just bad.

 public ThreadHandler(NH.NHandler NSH, int threadNum){
    this.threadNum=threadNum;
    this.NSH = NSH;
}

public ThreadHandler(OPA.OpaHandler SgeSH, int threadNum){
    this.threadNum=threadNum;
    this.OpaSH = OpaSH;
}

public ThreadHandler(SGE.SgeHandler SgeSH, int threadNum){
    this.threadNum=threadNum;
    this.SgeSH = SgeSH;
}

..... and on for 15

How would I implement a parent class to simply do

public ThreadHandler(objectType name, int threadNum){
    //Do stuff
}

Thanks for any help.


You need to create an interface, say, IHandler with common methods and all handlers should implement this interface

public interface IHandler {
      .... declare public methods
    } 
public NHandler implements IHandler  {
       .... implement all the methods declared in IHandler..
    }

Now you can just have the following in ThreadHandler

public ThreadHandler(IHandler  handler, int threadNum){
        .... call the methods
    }