Java Design Patterns
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package javadevjournal.design.structural.facade;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* @author Kunwar
|
||||
*/
|
||||
public class FacadePatternClient {
|
||||
private static int choice;
|
||||
|
||||
public static void main(String args[]) throws NumberFormatException, IOException {
|
||||
do {
|
||||
System.out.print("========= Mobile Shop ============ \n");
|
||||
System.out.print("1. IPHONE. \n");
|
||||
System.out.print("2. SAMSUNG. \n");
|
||||
System.out.print("3. NOKIA. \n");
|
||||
System.out.print("4. Exit. \n");
|
||||
System.out.print("Enter your choice: ");
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
choice = Integer.parseInt(br.readLine());
|
||||
ShopKeeper shopKeeper = new ShopKeeper();
|
||||
|
||||
switch (choice) {
|
||||
case 1: {
|
||||
shopKeeper.iphonePhoneSale();
|
||||
}
|
||||
break;
|
||||
case 2: {
|
||||
shopKeeper.samsungPhoneSale();
|
||||
}
|
||||
break;
|
||||
case 3: {
|
||||
shopKeeper.nokiaPhoneSale();
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
System.out.println("Nothing You purchased");
|
||||
}
|
||||
return;
|
||||
}
|
||||
} while (choice != 4);
|
||||
}
|
||||
}
|
||||
16
com/javadevjournal/design/structural/facade/IMobileShop.java
Normal file
16
com/javadevjournal/design/structural/facade/IMobileShop.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package javadevjournal.design.structural.facade;
|
||||
|
||||
/**
|
||||
* @author Kunwar
|
||||
*/
|
||||
public interface IMobileShop {
|
||||
/**
|
||||
* Mobile Model Number
|
||||
*/
|
||||
public void getMobileModelNumber();
|
||||
|
||||
/**
|
||||
* Mobile Price
|
||||
*/
|
||||
public void getMobilePrice();
|
||||
}
|
||||
16
com/javadevjournal/design/structural/facade/Iphone.java
Normal file
16
com/javadevjournal/design/structural/facade/Iphone.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package javadevjournal.design.structural.facade;
|
||||
|
||||
/**
|
||||
* @author Kunwar
|
||||
*/
|
||||
public class Iphone implements IMobileShop {
|
||||
@Override
|
||||
public void getMobileModelNumber() {
|
||||
System.out.println("The model is: IPhone 13");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMobilePrice() {
|
||||
System.out.println("The price is: 75000INR ");
|
||||
}
|
||||
}
|
||||
16
com/javadevjournal/design/structural/facade/Nokia.java
Normal file
16
com/javadevjournal/design/structural/facade/Nokia.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package javadevjournal.design.structural.facade;
|
||||
|
||||
/**
|
||||
* @author Kunwar
|
||||
*/
|
||||
public class Nokia implements IMobileShop {
|
||||
@Override
|
||||
public void getMobileModelNumber() {
|
||||
System.out.println("The model is: Nokia 1100");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMobilePrice() {
|
||||
System.out.println("The price is: 1500INR ");
|
||||
}
|
||||
}
|
||||
16
com/javadevjournal/design/structural/facade/Samsung.java
Normal file
16
com/javadevjournal/design/structural/facade/Samsung.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package javadevjournal.design.structural.facade;
|
||||
|
||||
/**
|
||||
* @author Kunwar
|
||||
*/
|
||||
public class Samsung implements IMobileShop {
|
||||
@Override
|
||||
public void getMobileModelNumber() {
|
||||
System.out.println("The model is: Galaxy 11");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMobilePrice() {
|
||||
System.out.println("The price is: 85000INR ");
|
||||
}
|
||||
}
|
||||
34
com/javadevjournal/design/structural/facade/ShopKeeper.java
Normal file
34
com/javadevjournal/design/structural/facade/ShopKeeper.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package javadevjournal.design.structural.facade;
|
||||
|
||||
/**
|
||||
* @author Kunwar
|
||||
*/
|
||||
public class ShopKeeper {
|
||||
private IMobileShop iphone;
|
||||
private IMobileShop samsung;
|
||||
private IMobileShop nokia;
|
||||
|
||||
/**
|
||||
* no args constructor
|
||||
*/
|
||||
public ShopKeeper() {
|
||||
iphone = new Iphone();
|
||||
samsung = new Samsung();
|
||||
nokia = new Nokia();
|
||||
}
|
||||
|
||||
public void iphonePhoneSale() {
|
||||
iphone.getMobileModelNumber();
|
||||
iphone.getMobilePrice();
|
||||
}
|
||||
|
||||
public void samsungPhoneSale() {
|
||||
samsung.getMobileModelNumber();
|
||||
samsung.getMobilePrice();
|
||||
}
|
||||
|
||||
public void nokiaPhoneSale() {
|
||||
nokia.getMobileModelNumber();
|
||||
nokia.getMobilePrice();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user