纯制造和间接的区别 [英] Difference between Pure fabrication and Indirection

查看:148
本文介绍了纯制造和间接的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到教程和很好的例子来解释这两者之间的区别,但无法找到任何信息。

I was trying to find tutorials and good examples which would explain difference between those two, but not able to find any information.

纯制造和间接行为为中间对象创建和分配职责,任何人都可以解释这些设计模式之间的区别?

Pure fabrication and indirection acts to create and assign responsibilities to intermediate object, so could anyone explain what is difference between those design patterns?

谢谢!

推荐答案

如果要创建一个较低的组件之间的耦合。 Larman在应用UML和Patterns中建议的示例是TaxCalculatorAdapter类。为了屏蔽客户端不必知道可能的适配器的内部工作,他隐藏了间接的方法,只暴露了所需的API。这种间接方式将与适应者高度耦合,但只能松散耦合到客户端。

You use Indirection if you want to create a lower coupling between components. The example Larman suggests in Applying UML and Patterns is a class TaxCalculatorAdapter. In order to shield clients from having to know inner workings of a possible adapter, he hides them with an indirection, only exposing the required API. This Indirection will be highly coupled to the adaptees, but only loosely coupled to the clients.

PersistentStorage 确实是一个 Indirecton (Larman在本书中这样说),因为它提供了较低的耦合。 Pure Fabrication 超越了它,尽管它创建了不属于您的域模型的对象。

The PersistentStorage from Pure Fabrication is indeed an Indirecton (Larman states so in the book) in that it provides lower coupling. Pure Fabrication goes beyond that though in that it creates objects that are not part of your Domain Model.

示例Larman give是一个域类销售。由于销售具有要保存的所有数据,所以它将成为保存销售逻辑的候选人(信息专家)。然而,持久性逻辑与销售的概念无关,因此该类将变得不够。此外,通过将销售耦合到特定的DB API,您可以限制重用(间接寻求拯救)。并且因为保存是一般的活动,所以您可能还会在还需要保存的对象中重复代码。为了避免这种情况,你可以做一些事情(纯粹的制作),这意味着你创建一些不属于域模型的东西(这里是一个 PersistentStorage ),但仍然捕获一个您的应用程序中的基本活动。

The example Larman gives is a domain class Sale. Since Sale has all the data to save, it would be a candidate to hold the logic for saving a Sale as well (Information Expert). However, persistence logic is not related to the concept of a Sale, hence the class would become incohesive. Also, by coupling the Sale to a particular DB API, you limit reuse (Indirection to the rescue). And because saving is a general activity, you would likely also duplicate code in objects which also need to be saved. To avoid this, you make something up (the pure fabrication), meaning you create something that is not part of the Domain model (here: a PersistentStorage), but still captures an essential activity in your application.

因此,Pure Fabrication是一种专业化,也可以是间接方式的变体。

As such, Pure Fabrication it is a specialization or rather a variant of Indirection.

这篇关于纯制造和间接的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆