it's me again with my legacy Java App. I have a core class that handles a lot of the important logic in the App. Let's called it MyManager. MyManager inherits from a class in a library, let's call it TopManager. The constraint is you can't modify any of these definition.
public class MyManager extends TopManager {
public MyManager(String a, String b){
super(a);
initialize(b);
}
public MyManager(){
this(null,null);
}
private void initialize(String b){
//specific implementation
}
}
public class TopManager {
public TopManager(String s){
//some implementation
}
}
I want to create a class CustomManager who have all the MyManager features but using TopManager default constructor.
public class CustomManager extends MyManager
public CustomManager(){
//super(); NO should call TopManager constructor
}
Since it's not possible in Java, I am looking for other bright ideas
I want to create a class CustomManager who have all the MyManager features
yes, using composition
but using
TopManagerdefault constructor.
by using generalization
class CustomManager extends TopManager { // have all properties of TopManager
private MyManager myManager; // have all behaviours of MyManager by delegating the call
}
Your CustomManager should inherit from TopManager instead of MyManager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With