将适配器与外观一起使用

发布于 2024-10-13 02:12:58 字数 393 浏览 1 评论 0原文

我的架构以前使用外观通过一组简单的方法来执行许多任务。就像:

startComputer(...)
shutdownComputer(...)

当我扩展应用程序时,我需要将多种类型的输入转换为外观本身。假设过去 startComputer 需要 6 个参数,而在新架构中,它需要某种可解析的字符串输入,而在另一种情况下,则需要一些 Base-64 编码的混乱。基本上,我想通过高级命令访问相同的子系统,但定义采用各种格式的接口。

当我开始考虑适配器与外观时,我感到很困惑——也许特别是因为人们总是在描述差异。在这种情况下,我本质上想要的(我认为)是使适配器支持各种输入,同时保持外观不变。在这种情况下,外观就是适应者。

这有意义还是有更好的方法?

My architecture previously was using a facade to perform a number of tasks through a simple set of methods. Something like:

startComputer(...)
shutdownComputer(...)

As I expand the application, I have the need to translate multiple types of input to the facade itself. Let's say that in the past startComputer took 6 parameters, and in the new architecture it takes some sort of parseable string input, and in another case, some base-64 encoded mess. Basically, across the board, I want to access the same sub-system through high-level commands, but define interfaces that take all sorts of formats.

I get confused when I start thinking about adapters vs. facades -- maybe especially because people are always delineating the differences. In this case, what I essentially want (I think) is to make adapters to support various inputs while keeping the facade as is. In this case, the facade is the adaptee.

Does this make sense or is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-10-20 02:12:58

听起来你希望你的外观使用“命令”模式来定义它的参数
http://en.wikipedia.org/wiki/Command_pattern

sounds like you want your facade to use the "command" pattern to define it's parameters
http://en.wikipedia.org/wiki/Command_pattern

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文