Design Pattern, Software Development

The Facade Design Pattern In Simple Words

Do you have codes with an overwhelming number of service and DAO methods? Which group of method calls represent which use case? If that is one of the predicaments you are having with your codebase, it is probably wise to logically group methods into Facades. The Facade design pattern is a structural design pattern that creates a unified interface using existing codes.

The Problem With Layering

Layering happens when we create service and DAO layers. The grouping of methods in the classes and interfaces often does not represent any use case. As the number of methods increases, maintaining the classes and interfaces becomes cumbersome. Moreover, the sheer number of codes drowns out any use-case hints. We can group these method codes representing some contexts or use cases with the Facade design pattern.

Consider the following pseudo-classes. If you look into the codes to enhance an existing feature, it is hard to tell which methods you can use without digging.

Without modifying these classes, we can create a Facade class reusing them. For example, we can create a UpdateStudentGradeFacade class that uses methods from the StudentService, and TeacherService classes.

With the Facade design pattern, we are not replacing any methods. Therefore, other codes can still use or extend them. Do you get the idea?

The Facade Pattern Off The Gang of Four

The Gang of Four briefly describes the Facade pattern’s intent.

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

The unified interface represents the UpdateStudentGrade class that uses two services in our code example. These services represent the subsystems in our codes.

Other Design Patterns

The Facade design pattern is only one of the structural design patterns we can use to create maintainable software applications. Check out the other design patterns on Design Patterns Are The Ultimate Toolkit For Programmers.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like