Jump to content

Facade design pattern

Go to solution Solved by FuzzyLogic,

A facade class can be as complicated or simple as you need it to, since all it's really doing is providing abstraction for the user. So, the goal is to make the code that calls methods from the facade class simple, but the facade itself doesn't necessarily need to be simple.

 

As an example, I've used facade classes to aid in performing MySQL database queries. To do this, I've written methods like findWithID(id) or findWithHeightBetween(min, max) within the facade class that return a list of all the database entries matching the input. Here, the facade class allows the user to call a single method to get data from the database without needing to know anything about the underlying system or memorize a complicated database query.

 

So,

Facade class code: Doesn't really matter how simple it is

Caller code: Should be simpler as a result of using the facade

 

Hope this helps

So as I understand the facade design pattern lets the user access a complicated system through a facade in the name of better user friendliness, but if I am making a facade design pattern program, does the facade class need to be simple and user friendly, or does the program that accesses the facade class need to be user friendly and just call the facade and then everything complicated happens in the facade where there might be like a lot of methods that call other methods and give the user what they request?

 

Link to comment
https://linustechtips.com/topic/1466428-facade-design-pattern/
Share on other sites

Link to post
Share on other sites

A facade class can be as complicated or simple as you need it to, since all it's really doing is providing abstraction for the user. So, the goal is to make the code that calls methods from the facade class simple, but the facade itself doesn't necessarily need to be simple.

 

As an example, I've used facade classes to aid in performing MySQL database queries. To do this, I've written methods like findWithID(id) or findWithHeightBetween(min, max) within the facade class that return a list of all the database entries matching the input. Here, the facade class allows the user to call a single method to get data from the database without needing to know anything about the underlying system or memorize a complicated database query.

 

So,

Facade class code: Doesn't really matter how simple it is

Caller code: Should be simpler as a result of using the facade

 

Hope this helps

Computer engineering PhD student and RFML researcher

 

Daily Driver:

CPU: Ryzen 7 4800H | GPU: RTX 2060 | RAM: 32GB DDR4 3200MHz C16 | OS: Debian 13

 

Gaming PC:

CPU: Ryzen 5 5600X | GPU: EVGA RTX 2080Ti | RAM: 32GB DDR4 3200MHz C16 | OS: Windows 11

Link to comment
https://linustechtips.com/topic/1466428-facade-design-pattern/#findComment-15646559
Share on other sites

Link to post
Share on other sites

1 minute ago, dcgreen2k said:

A facade class can be as complicated or simple as you need it to, since all it's really doing is providing abstraction for the user. So, the goal is to make the code that calls methods from the facade class simple, but the facade itself doesn't necessarily need to be simple.

 

As an example, I've used facade classes to aid in performing MySQL database queries. To do this, I've written methods like findAll or findWithID within the facade class that return a list of all the database entries matched the input. Here, the facade class allows the user to call a single method to get data from the database without needing to know anything about the underlying system or memorize a complicated database query.

 

So:

Facade class code: Doesn't really matter how simple it is

Caller code: Should be simpler as a result of using the facade

 

Hope this helps

It helps, thanks a lot! Now I can be sure that I understood it correctly.

Link to comment
https://linustechtips.com/topic/1466428-facade-design-pattern/#findComment-15646563
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×