Design Patterns Projject
Design Patterns Projject
Justification
The facade design pattern is a structural design pattern. This helps in
simplifying the way of interacting with various entities.
INTENT
MOTIVATION
STRUCTURE DIAGRAM
PARTICIPANTS
• Facade (Package)
• knows which subsystem classes are responsible for a request.
• delegates client requests to appropriate subsystem objects. • subsystem
classes (Flight, Transfer, Hotel)
• implement subsystem functionality.
• handle work assigned by the Facade object.
• have no knowledge of the facade; that is, they keep no references to it.
CONSEQUENCES
COLLABORATION
IMPLEMENTATION
Interfaces are created for each subsystems using Java. (Since java does not
support multiple inheritance, it could be achieved using Interfaces)
SAMPLE CODE:
1.FacadeClient.java
This will act as a client which will invoke our facade.
2) FlightBooking.java
The below implementation will be sample code for flight booking interface.
3) FlightBookingImpl.java
The below code will be sample code for flight booking implementation.
public class FlightBookingImpl implements FlightBooking {
@Override
public void book(){
System.out.println("Flight booked successfully");
}
}
4) HotelBooking.java
The below code will act as the hotel booking interface.
HotelBookingImpl.java
The below code will act as the hotel booking implementation.
5) TransferBooking.java
The below code will act as the transfer booking interface.
TrasnferBookingImpl.java
The below code will act as the transfer booking implementation.
TravelPackageFacadeImpl.java
The below code will act as the facade implementation.
HotelBooking hotelBooking=new
HotelBookingImpl();hotelBooking.book();
FlightBooking flightBooking=new
FlightBookingImpl();flightBooking.book();
OUTPUT:
ADVANTAGES OF FAÇADE PATTERN
A facade can make a software library easier to use, understand and test,
since the facade has convenient methods for common tasks. - make the
library more readable, for the same reason.
- reduce dependencies of outside code on the inner workings of a library, since
most code uses the facade, thus allowing more flexibility in developing the
system
- wrap a poorly designed collection of APIs with a single well-designed API
Justification
The facade design pattern is a structural design pattern. This helps in
simplifying the way of interacting with various entities.
Intent
● Considering a Travel package booking system. Usually when you try to book a
package, the ticket booking system interacts with many of subsystems.
● The various sub-systems may be flight, hotel and cab booking . In addition to this
may also interact with many other sub systems.
● In this case instead of client having the overhead of interacting with various other
subsystems , we can introduce a facade layer which interacts will all these
subsystems. Finally once it get the response from all the subsystems, it aggregates
all these response and send the response back to the client.
Applicablity
● Facade (Package)
○ knows which subsystem classes are responsible for a request
○ delegates client requests to appropriate subsystem objects
● Subsystem classes (Flight, Transfer, Hotel)
○ Implement subsystem functionality.
○ Handle work assigned by the Facade object
Consequences
2. It promotes weak coupling between the subsystem and its clients. Often
the components in a subsystem are strongly coupled.
3. It doesn't prevent applications from using subsystem classes if they need to.
Collaboration
Interfaces are created for each subsystems using Java. (Since java does not
support multiple inheritance, it could be achieved using Interfaces)
Sample Code
Thank You