When you are using an ATM, and you want to withdraw some amount, for instance, 10,000 Rupees. So, you need to insert your bank debit card in the ATM and enter the required password which is the passcode. Once you trigger the 10000 amount button, the following things will happen behind the screen.First, the machine will check if the account is valid or not. Then it will check whether you have sufficient funds to withdraw the entered amount. Then it’ll check whether the pin code is correct or not. After validating all these things, the amount will be withdrawn. This complicated procedure is handled behind the screen, but for the user, the interface is pretty simple.
Another example is a building that has ten floors with 2-3 rooms each. For a quality purpose, you’d need cement and bricks, etc. Here to build the structure you need to maintain many things which is a complex process.
You will give this task to the building contractor who will manage these things in a better manner. You’ll pay him 5,00,000 Rupees to that contractor, and you will explain him with your ideas. Then that contractor will handle these complicated things on behalf of us.
public interface Menu { public void showMenu(); }
public class VegMenu implements Menu { @Override public void showMenu() { System.out.println("Idly"); System.out.println("Dosa"); System.out.println("Vada"); } }
public class NonVegMenu implements Menu { @Override public void showMenu() { System.out.println("Chicken Biriyani"); System.out.println("Tandoori"); } }
public class HotleServiceStaff { private VegMenu vegMenu; private NonVegMenu nonVegMenu; public HotleServiceStaff() { this.vegMenu=new VegMenu(); this.nonVegMenu=new NonVegMenu(); } public void showVegMenu() { this.vegMenu.showMenu(); } public void showNonVegMenu() { this.nonVegMenu.showMenu(); } public void showVegNonVegMenu() { this.vegMenu.showMenu(); this.nonVegMenu.showMenu(); } }
public class FacadeEx { public static void main(String[] args) { HotleServiceStaff hotleServiceStaff=new HotleServiceStaff(); System.out.println("Veg Menu"); hotleServiceStaff.showVegMenu(); System.out.println("--------"); System.out.println("Non Veg Menu"); hotleServiceStaff.showNonVegMenu(); System.out.println("--------"); System.out.println("Veg & Non Veg Menu"); hotleServiceStaff.showVegNonVegMenu(); } }