Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Design pattern at work what does facade pattern mean

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what is the meaning of the facade pattern in the work". In the daily operation, I believe that many people have doubts about the meaning of the facade pattern in the work. The editor consulted all kinds of data and sorted out the simple and easy-to-use operation method. I hope it will be helpful for everyone to answer the doubt of "what is the meaning of the facade pattern in the work"? Next, please follow the editor to study!

1 use the scene

The facade pattern can be said to be a design pattern that is widely used at work, such as the commonly used slf4j.

The following is a brief introduction to common usage scenarios:

Design a unified portal for remote interfaces

For example, you need to call Wechat Alipay, in which there are a lot of parameters, and the parameters are not the same. At this time, you can uniformly encapsulate an interface, and then when friends use it, you only need to call the encapsulated API.

Don't worry about the same status. It's called status here and orderStatus there. Anyway, the outside world is a unified facade, you can define it yourself.

Benefits

The advantage of a unified package is that it can be Mock.

This is also what I have learned recently. It was all wordy before, who cares about junit.

Mock means that in a junit test, you inject a mock object using @ MockBean and then define the return yourself.

Mockito.when (xxxFacadeService.methodX ()) .thenReturn (mockBean)

It is the object that returns its own mock when an interface is called.

I just discovered this, too, because I tried to annotate the objects of the Dubbo interface with @ MockBean, but it didn't work.

However, it is still flexible. All the places that call the external interface, whether it is http or dubbo, all encapsulate the facade, so I mock my own facade interface ok.

At this point, the study on "what is the meaning of facade pattern at work" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report