To demonstrate Open/Closed principle of SOLID principle, I implemented the following code.
Code:
interface IFaculty{
void admin();
}
class ITFac implements IFaculty{
@Override
public void admin() {
System.out.println("IT Fac Admin");
}
}
class MedFac implements IFaculty{
@Override
public void admin(){
System.out.println("Med Fac Admin");
}
}
class University{
public void adminFaculty(IFaculty iFaculty){
iFaculty.admin();
}
}
To test the above code, I tried to call the adminFaculty() method in the main method of main class as follows.
Code:
public class Main {
public static void main(String[] args) {
University u1 = new University();
u1.adminFaculty(); // cannot call this method without passing parameters
}
}
But I cannot call the method without passing the relevant parameter: an object of IFaculty. But I cannot do so. Does anybody knows how to call the adminFaculty(), from the main method? or any way to call the adminFaculty() and run the code to give relavent output.?
Thank you.