Skip to content

Commit

Permalink
docs: Decorator, facade, proxy, chain, command intepreter
Browse files Browse the repository at this point in the history
Decorator, facade, proxy, chain, command intepreter
  • Loading branch information
luizrosalba committed Dec 12, 2021
1 parent 03539d5 commit 219c968
Show file tree
Hide file tree
Showing 79 changed files with 1,191 additions and 1 deletion.
Binary file added 10- Decorator Pattern/ChineeseFood.class
Binary file not shown.
27 changes: 27 additions & 0 deletions 10- Decorator Pattern/ChineeseFood.java
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;

}

}
Binary file added 10- Decorator Pattern/Decorator.PNG
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.
92 changes: 92 additions & 0 deletions 10- Decorator Pattern/DecoratorPatternCustomer.java
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 added 10- Decorator Pattern/Food.class
Binary file not shown.
9 changes: 9 additions & 0 deletions 10- Decorator Pattern/Food.java
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 added 10- Decorator Pattern/FoodDecorator.class
Binary file not shown.
28 changes: 28 additions & 0 deletions 10- Decorator Pattern/FoodDecorator.java
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 added 10- Decorator Pattern/NonVegFood.class
Binary file not shown.
28 changes: 28 additions & 0 deletions 10- Decorator Pattern/NonVegFood.java
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 added 10- Decorator Pattern/VegFood.class
Binary file not shown.
20 changes: 20 additions & 0 deletions 10- Decorator Pattern/VegFood.java
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 added 11-Facade Pattern/Blackberry.class
Binary file not shown.
16 changes: 16 additions & 0 deletions 11-Facade Pattern/Blackberry.java
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 ");

}

}
Binary file added 11-Facade Pattern/Facade.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 11-Facade Pattern/FacadePatternClient.class
Binary file not shown.
79 changes: 79 additions & 0 deletions 11-Facade Pattern/FacadePatternClient.java
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 added 11-Facade Pattern/Iphone.class
Binary file not shown.
16 changes: 16 additions & 0 deletions 11-Facade Pattern/Iphone.java
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 added 11-Facade Pattern/MobileShop.class
Binary file not shown.
9 changes: 9 additions & 0 deletions 11-Facade Pattern/MobileShop.java
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 added 11-Facade Pattern/Samsung.class
Binary file not shown.
16 changes: 16 additions & 0 deletions 11-Facade Pattern/Samsung.java
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 added 11-Facade Pattern/ShopKeeper.class
Binary file not shown.
45 changes: 45 additions & 0 deletions 11-Facade Pattern/ShopKeeper.java
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 added 12-Proxy Pattern/OfficeInternetAccess.class
Binary file not shown.
Loading

0 comments on commit 219c968

Please sign in to comment.