Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
54 views

Design Patterns Projject

The document describes applying the facade design pattern to a travel package booking system. The facade pattern provides a simple, unified interface to complex subsystems like flight, hotel, and cab booking. This simplifies client access to the various subsystems and reduces dependencies. The implementation creates interfaces for each subsystem and a facade interface that delegates requests to the appropriate subsystem interfaces. The facade pattern shields clients from subsystem complexity and promotes loose coupling between subsystems and clients.

Uploaded by

Rohith M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Design Patterns Projject

The document describes applying the facade design pattern to a travel package booking system. The facade pattern provides a simple, unified interface to complex subsystems like flight, hotel, and cab booking. This simplifies client access to the various subsystems and reduces dependencies. The implementation creates interfaces for each subsystem and a facade interface that delegates requests to the appropriate subsystem interfaces. The facade pattern shields clients from subsystem complexity and promotes loose coupling between subsystems and clients.

Uploaded by

Rohith M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

PROBLEM STATEMENT

• When you want to provide simple interface to a complex sub-system.


• When several dependencies exist between clients and the implementation
classes of an abstraction.
• Facade design pattern can be applied at any point of development, usually
when the number of interfaces grow and system gets complex.
• Facade design pattern is more like a helper for client applications, it doesn’t
hide subsystem interfaces from the client. Whether to use Facade or not is
completely dependent on client code.

Chosen pattern: Facade Pattern

Justification
The facade design pattern is a structural design pattern. This helps in
simplifying the way of interacting with various entities.

INTENT

• Provide a unified interface to a set of interface(s) in a subsystem.


• Facade defines a higher-level interface that makes the subsystem easier to
use.

Package Booking System


• 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.
APPLICABILITY

• Users who wish to book vacation packages should be able


• To book their stay in any hotel nearby,
• To book their flight tickets,
• To book cabs to wander around the city.
• The system must contain interfaces or subsystems in general term such
as for Client, hotels, flight booking, cab booking etc.,
• This may include more number of subsystems as well.
Following is an implementation of the Package booking system considering the
above conditions using the Facade Pattern.

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

The Facade pattern offers the following benefits:


1. It shields clients from subsystem components, thereby reducing the
number of objects that clients deal with and making the subsystem easier to use.
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

• Clients communicate with the subsystem by sending requests to Facade,


which forwards them to the appropriate subsystem object(s). Although the
subsystem objects perform the actual work, the facade may have to do work
of its own to translate its interface to subsystem interfaces.
• Clients that use the facade don't have to access its subsystem objects directly.

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.

public class FacadeClient{


public static void main(String[] args){
TravelPackageFacade travelPackageFacade=new
TravelPackageFacadeImpl();travelPackageFacade.book();
}
}

2) FlightBooking.java
The below implementation will be sample code for flight booking interface.

public interface FlightBooking {


public void book();
}

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.

public interface HotelBooking {


public void book();
}

HotelBookingImpl.java
The below code will act as the hotel booking implementation.

public class HotelBookingImpl implements HotelBooking{


@Override
public void book(){
System.out.println("Hotel booked successfully");
}
}

5) TransferBooking.java
The below code will act as the transfer booking interface.

public interface TransferBooking {


public void book();
}

TrasnferBookingImpl.java
The below code will act as the transfer booking implementation.

public class TrasnferBookingImpl implements TrasnferBooking{


@Override
public void book(){
System.out.println("Transfer booked successfully");
}
}
6) TravelPackageFacade.java
The below code will act as the facade interface.

public interface TravelPackageFacade {


public void book();
}

TravelPackageFacadeImpl.java
The below code will act as the facade implementation.

public class TravelPackageFacadeImpl implements TravelPackageFacade{


@Override
public void book() {
TrasferBooking trasferBooking=new
TrasferBookingImpl();trasferBooking.book();

HotelBooking hotelBooking=new
HotelBookingImpl();hotelBooking.book();

FlightBooking flightBooking=new
FlightBookingImpl();flightBooking.book();

System.out.println("Travel package booked successfully");


}
}

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

DISADVANTAGES OF FAÇADE PATTERN

• Adds a layer of indirection which may affect performance,


• May make your code base bigger, and
• Developers will need to learn to use this bespoke API (whereas they may be
very familiar with the library)
TRAVEL PACKAGE BOOKING
SYSTEM

Pattern Used - Facade


Team Members:
18MIS0170 - NEYAVANAN V
18MIS0190 - MONISH KUMAR S
Problem Statement

● When you want to provide simple interface to a complex sub-system.


● When several dependencies exist between clients and the implementation
classes of an abstraction.
● Facade design pattern can be applied at any point of development, usually when
the number of interfaces grow and system gets complex
Chosen Pattern : Facade

Justification
The facade design pattern is a structural design pattern. This helps in
simplifying the way of interacting with various entities.
Intent

● Provide a unified interface to a set of interface(s) in a subsystem


● Facade defines a higher-level interface that makes the subsystem
easier to use.
About the System

● 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

● Users who wish to book vacation packages should be able


● To book their stay in any hotel nearby,
● To book their flight tickets,
● To book cabs to wander around the city.
● The system must contain interfaces or subsystems in general term such as for
Client, hotels, flight booking, cab booking etc.,
● This may include more number of subsystems as well.
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
Consequences

1. It shields clients from subsystem components, thereby reducing the number


of objects that clients deal with and making the subsystem easier to use.

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

● Clients communicate with the subsystem by sending requests to Facade,


which forwards them to the appropriate subsystem object(s). Although the
subsystem objects perform the actual work, the facade may have to do work
of its own to translate its interface to subsystem interfaces.
● Clients that use the facade don't have to access its subsystem objects
directly.
Implementation

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

You might also like