Problem Statement: We have multiple class files (~200+), which each implement different methods and some use the methods from each other also to implement their own methods.
We wish to call multiple of these class methods (~20-30) in our code and have them deliver functionality like writing to a UI Web page and reading from a web page.
As we wish to make this process simple, we want a single class/interface which contains all these multiple class references (~200+), and we just need to import/include this single class/interface in our code and then using it to reference all the methods in the class files.
Question: Is the above possible? If so, how - by using a class or interface or something else?
I have provided examples and information of what we have tried here: Implement multiple classes in the same interface in Java?
Basically, we have tried
- Creating a Class which has all the other class declared in it
- Creating an interface, which has implementations across the multiple classes (the ~200+ mentioned above)
- Implemented a class and an interface
Nope of the ways seem to work.
As a gist of what we want in code, have provided an example below.
Example (this is not the right code or implementation, just wanted to provide an example of what we want to do in code):
I have 2 classes called "ABC_FamilyGivenName" & "ABC_DOBGender". I have created an interface "Common".
I want to use the methods in both the above classes in my code in class "Application".
With the current implementation, Java wants me to add an @Override to both the ABC_FamilyGivenName & ABC_DOBGender. This again creates an overhead, if we have ~500 such methods, and will thus need to override all ~500 in each of the c~200 class files??
***INTERFACE***:
public interface Common {
void ABC_GivenNames();
void ABC_FamilyNames();
void ABC_Gender();
void ABC_BirthDay();
}
***IMPLEMENTATION CLASSES***:
**ABC_FamilyGivenName**
public class ABC_FamilyGivenName extends Base implements Common {
public void ABC_GivenNames(){
// Implementation code
}
public void ABC_FamilyNames(){
// Implementation code
}
}
**ABC_DOBGender**
public class ABC_DOBGender extends Base implements Common {
public void ABC_Gender(){
// Implementation code
}
public void ABC_BirthDay(){
// Implementation code
}
}
**USE IMPLEMENTED CLASS IN CODE**:
public class Application extends Base {
Common commonClass = new ABC_FamilyGivenName();
/* *DO I NEED THIS? I THINK I DO, BUT CODE/JAVA SAYS I DO NOT*
* Common commonClass = new ABC_DOBGender();
*/
public void ELP_C0050_PassportDetails(){
commonClass.ABC_GivenNames();
commonClass.ABC_FamilyNames();
commonClass.ABC_DOB();
commonClass.ABC_Gender();
}
}