Java Structural Design Patterns – Facade Pattern

Facade Pattern provides the ease of usability for a system by hiding its complexity. It comes under a Structural design pattern. In this pattern client code can access the system but it hides the working of the system by providing a simpler interface to use for client. In this pattern one class gets created (FACADE) which includes user defined functions and delegates providing calls to the classes belongs to the system. Now the client code interacts only with Facade, not with the actual system.

If your solution or project has below concerns you can consider using Facade Pattern:

  • Need simpler API to improve the readability and usability of a software library
  • Aggregate functionalities or interface APIs based on Context
  • A flexible framework is required to subclass or extending functionality.

<Here are ALL other Java Design Patterns, explained in detail with examples>

Facade Pattern by Example

We will understand this pattern using the simple concept of an Animal speaking. We will define an interface and a couple of animals will implement it.

Concrete Animal Classes

one more

Let us add the facade and supporting methods

Running the Example

Output

Conclusion

Facade pattern does beautiful work by hiding all the complexities of your system and provides a simpler interface API to use. You can use this patterns if an entry point is needed to each level of layered software, or
the abstractions and implementations of a subsystem are tightly coupled.

The source code is available in our Github repository.

Download Code

 

<Here are ALL other Java Design Patterns, explained in detail with examples>

Add a Comment

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