samedi 26 mai 2018

Java Issue in Object Constuction / Inheritance / Generics

Suppose I have a class ApiClient (auto-generated) which does not implement an Interface.

There is another class X which extends ApiClient to have some additional and overriding methods.

class X extends ApiClient{
  X (Settings s){
    super();
    this.setPropertyInheritedfromApiClient-A("food");
    this.setPropertyInheritedfromApiClient-B(thisClassMethod());
 } 

  thisClassMethod(){ return "wee" ; }      

}

There would be similar type of class X and each would derive from class identical to ApiClient but since these are aut-generated , packages will differ and values of certain fields will be different like url. To digress , each ApiClient represents a different WebService endpoint.

Although I can keep writing class similar to X for each corresponding to each ApiClient ( defined for different WebService Endpoint ) but the logic essentially remains the same.

I would want something like

class X extends T {
 X (Settings s){
        super();
        this.setPropertyInheritedfromApiClient-A("food"); // FAIL since Type of super class is not known
        this.setPropertyInheritedfromApiClient-B(thisClassMethod()); //FAIL
     } 

}

How can i approach this problem from Java Generics way or which Design Pattern to apply ?

I am not able to think of the title of the Question - Please suggest

Aucun commentaire:

Enregistrer un commentaire