Difference between Pure fabrication and Indirectio

2019-04-04 18:16发布

问题:

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?

Thanks!

回答1:

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.

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.

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.

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



回答2:

Pure fabrication class is a type of class ,which does not concept in a problem domain designed ,This class is assigned with high cohesion ^,low coupling & reuse. Indirection It solves the problem of assigning the responsibility of avoiding direct coupling between things.it also ensures low coupling between the objects & maintains higher reside capabilities.