Facade Pattern in Java

Facade Pattern is a Structural Pattern in which, a set of interfaces is gathered into only one interface that Client can work easily and simply. Facade Pattern helps us to wrap complexities of components inside and lose coupling between Client and subSystems.

I. OVERVIEW

Facade Pattern defines a higher interface/object – Facade – that wraps some lower interfaces/objects. Whenever Client wants to make a chain of complex actions which require many methods and interaction, it just call one simple Facade method, all operation can be done inside that method.
facade-pattern-overview
You can see that Facade object contains other interfaces/objects (A, B, C) and manages their operation by doWork() method.

II. PRACTICE
1. Project Overview

Assume that we have some operations such as: register, consultation, healthcare that a Customer will be served when applying for our company’s Customer Services.

With Facade Pattern, Client only need to create Customer Information, then calls FacadeService setServiceforCustomer() method. All works containing register information, Consultation Service and HealhCare Service will be processed behind.
facade-pattern-demo

2. Step by Step

2.1- Create Customer class:

2.2- Create ICustomerService interface:

2.3- Create implementations of ICustomerService interface:

Consultation.java

HealthCare.java

2.4- Create FacadeService class:

2.5- Create Client Test Class:

2.6- Run the code, the console window shows:

III. SOURCE CODE

FacadePattern


Related Posts



Got Something To Say:

Your email address will not be published. Required fields are marked *

*