If you can change CusClass1 and CusClass2 , you can create an interface
public interface AttributeProvider { Object getAttrib1();
and then make sure that CusClass1 and CusClass2 implement this interface:
public class CusClass1 implements AttributeProvider { ... }
then you can have a constructor with this interface:
public MyClass(AttributeProvider myObject) { globalVar1 = myObject.getAttrib1(); globaVar2 = myObject.getAttrib2(); }
This way you will not need to modify MyClass if you create a new CusClass3 , which should also be used in MyClass
source share