Skip to content

Commit f013ff8

Browse files
committed
Proxy and Facade design pattern
1 parent 584a575 commit f013ff8

19 files changed

Lines changed: 711 additions & 0 deletions

facade/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'org.example'
6+
version '1.0-SNAPSHOT'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
14+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
15+
}
16+
17+
test {
18+
useJUnitPlatform()
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

facade/gradlew

Lines changed: 185 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

facade/gradlew.bat

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

facade/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'facade'
2+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class DeliveryBoy {
2+
public void pickUpOrder() {
3+
4+
}
5+
public void deliverOrder() {
6+
7+
}
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class DeliveryTeam {
2+
public void assignDeliveryBoy() {
3+
4+
}
5+
}

facade/src/main/java/Main.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Facade pattern : This is also a structural pattern where it defines how classes needs to be structured in a way that
3+
* for complex functionalities there is single entry point to that function.
4+
* We should use facade pattern when we have complex subsystems , calling each leads to a single operation for client.
5+
* In this case we should introduce facade which helps to do interaction with all this subsystem and gives us single output,
6+
* Facade pattern basically adds one level of abstractions in the system.
7+
*
8+
* To implement facade you have to write one class which interacts with other services in down stream.
9+
*
10+
* Consider example you have to place order in the zomato and you want to get food
11+
* 1. Customer sees menu and place order
12+
* 2. Restaurant got this order and prepare order
13+
* 3. Delivery team assigns delivery person
14+
* 4. Delivery boy picks up order and deliver.
15+
*
16+
* Here Zomato api is facade for us where we just clicked place order and it done. Think to get food
17+
* after placing order you have to call restaurant to prepare order and give it to delivery boy.
18+
*
19+
* https://www.decipherzone.com/blog-detail/facade-design-pattern
20+
*/
21+
public class Main {
22+
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Restaurant {
2+
public void prepareOrder() {
3+
4+
}
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class ZomatoFacade {
2+
private Restaurant restaurant;
3+
private DeliveryBoy deliveryBoy;
4+
private DeliveryTeam deliveryTeam;
5+
6+
public void placeOrder() {
7+
restaurant.prepareOrder();
8+
deliveryTeam.assignDeliveryBoy();
9+
deliveryBoy.pickUpOrder();
10+
deliveryBoy.deliverOrder();
11+
}
12+
}

0 commit comments

Comments
 (0)