-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Decorator, facade, proxy, chain, command intepreter
Decorator, facade, proxy, chain, command intepreter
- Loading branch information
1 parent
03539d5
commit 219c968
Showing
79 changed files
with
1,191 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
public class ChineeseFood extends FoodDecorator | ||
{ | ||
|
||
|
||
|
||
public ChineeseFood(Food newFood) | ||
{ | ||
super(newFood); | ||
|
||
} | ||
|
||
|
||
public String prepareFood() | ||
{ | ||
return super.prepareFood() +" With Fried Rice and Manchurian "; | ||
|
||
} | ||
|
||
|
||
public double foodPrice() | ||
{ | ||
return super.foodPrice()+65.0; | ||
|
||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
|
||
public class DecoratorPatternCustomer { | ||
|
||
|
||
private static int choice; | ||
|
||
public static void main(String args[]) throws NumberFormatException, IOException | ||
{ | ||
|
||
do{ | ||
System.out.print("========= Food Menu ============ \n"); | ||
System.out.print(" 1. Vegetarian Food. \n"); | ||
System.out.print(" 2. Non-Vegetarian Food.\n"); | ||
System.out.print(" 3. Chineese Food. \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()); | ||
|
||
|
||
|
||
switch (choice) { | ||
case 1: | ||
|
||
{ | ||
|
||
|
||
|
||
VegFood vf=new VegFood(); | ||
|
||
|
||
System.out.println(vf.prepareFood()); | ||
|
||
System.out.println( vf.foodPrice()); | ||
|
||
|
||
|
||
} | ||
break; | ||
|
||
case 2: | ||
|
||
{ | ||
|
||
|
||
Food f1=new NonVegFood((Food) new VegFood()); | ||
|
||
System.out.println(f1.prepareFood()); | ||
|
||
System.out.println( f1.foodPrice()); | ||
|
||
|
||
} | ||
break; | ||
|
||
case 3: | ||
|
||
|
||
{ | ||
|
||
|
||
|
||
Food f2=new ChineeseFood((Food) new VegFood()); | ||
|
||
|
||
System.out.println(f2.prepareFood()); | ||
|
||
System.out.println( f2.foodPrice()); | ||
|
||
} | ||
break; | ||
|
||
|
||
default: | ||
{ | ||
System.out.println("Other than these no food available"); | ||
|
||
} | ||
return; | ||
} | ||
|
||
}while(choice!=4); | ||
|
||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
public interface Food { | ||
|
||
public String prepareFood(); | ||
|
||
public double foodPrice(); | ||
|
||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
public abstract class FoodDecorator implements Food | ||
|
||
{ | ||
private Food newFood; | ||
|
||
public FoodDecorator(Food newFood) | ||
{ | ||
|
||
this.newFood=newFood; | ||
|
||
} | ||
|
||
@Override | ||
public String prepareFood() | ||
{ | ||
return newFood.prepareFood(); | ||
|
||
} | ||
|
||
|
||
public double foodPrice() | ||
{ | ||
return newFood.foodPrice(); | ||
|
||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
public class NonVegFood extends FoodDecorator{ | ||
|
||
|
||
|
||
public NonVegFood(Food newFood) | ||
{ | ||
super(newFood); | ||
|
||
} | ||
|
||
|
||
|
||
public String prepareFood() | ||
{ | ||
return super.prepareFood() +" With Roasted Chiken and Chiken Curry "; | ||
|
||
} | ||
|
||
|
||
public double foodPrice() | ||
{ | ||
return super.foodPrice()+150.0; | ||
|
||
} | ||
|
||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
public class VegFood implements Food { | ||
|
||
|
||
public String prepareFood() | ||
{ | ||
|
||
return "Veg Food"; | ||
|
||
|
||
} | ||
|
||
public double foodPrice() | ||
{ | ||
|
||
return 50.0; | ||
|
||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
public class Blackberry implements MobileShop { | ||
|
||
@Override | ||
public void modelNo() { | ||
System.out.println(" Blackberry Z10 "); | ||
|
||
} | ||
|
||
@Override | ||
public void price() { | ||
System.out.println(" Rs 55000.00 "); | ||
|
||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
|
||
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. BLACKBERRY. \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 sk=new ShopKeeper(); | ||
|
||
switch (choice) { | ||
case 1: | ||
|
||
{ | ||
|
||
sk.iphoneSale(); | ||
|
||
} | ||
break; | ||
|
||
case 2: | ||
|
||
{ | ||
|
||
sk.samsungSale(); | ||
|
||
} | ||
break; | ||
|
||
case 3: | ||
|
||
|
||
{ | ||
|
||
|
||
sk.blackberrySale(); | ||
|
||
} | ||
break; | ||
|
||
|
||
default: | ||
{ | ||
System.out.println("Nothing You purchased"); | ||
|
||
} | ||
return; | ||
} | ||
|
||
}while(choice!=4); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
public class Iphone implements MobileShop { | ||
|
||
@Override | ||
public void modelNo() { | ||
System.out.println(" Iphone 6 "); | ||
|
||
} | ||
|
||
@Override | ||
public void price() { | ||
System.out.println(" Rs 65000.00 "); | ||
|
||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
public interface MobileShop { | ||
|
||
|
||
public void modelNo(); | ||
|
||
public void price(); | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
public class Samsung implements MobileShop { | ||
|
||
@Override | ||
public void modelNo() { | ||
System.out.println(" Samsung galaxy tab 3 "); | ||
|
||
} | ||
|
||
@Override | ||
public void price() { | ||
System.out.println(" Rs 45000.00 "); | ||
|
||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
public class ShopKeeper { | ||
|
||
|
||
private MobileShop iphone; | ||
private MobileShop samsung; | ||
private MobileShop blackberry; | ||
|
||
|
||
public ShopKeeper(){ | ||
|
||
iphone= new Iphone(); | ||
|
||
samsung=new Samsung(); | ||
|
||
blackberry=new Blackberry(); | ||
|
||
} | ||
|
||
|
||
|
||
public void iphoneSale(){ | ||
|
||
iphone.modelNo(); | ||
iphone.price(); | ||
|
||
} | ||
|
||
public void samsungSale(){ | ||
|
||
samsung.modelNo(); | ||
samsung.price(); | ||
|
||
} | ||
|
||
|
||
public void blackberrySale(){ | ||
|
||
blackberry.modelNo(); | ||
blackberry.price(); | ||
|
||
} | ||
|
||
|
||
} |
Binary file not shown.
Oops, something went wrong.