CSC/ECE 517 Fall 2010/ch7 7c ed: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
=Pure Fabrication=
=Pure Fabrication=
Pure Fabrication is a [http://en.wikipedia.org/wiki/GRASP_(object-oriented_design) GRASP] (General Responsibility Assignment Software Patterns) principle.
Pure Fabrication is a [http://en.wikipedia.org/wiki/GRASP_(object-oriented_design) GRASP] (General Responsibility Assignment Software Patterns) principle.
==Examples==
Larman provides an example of the Pure Fabrication pattern in his book ''Applying UML and Patterns''. [http://www.amazon.com/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0130925691/ref=sr_11_1?ie=UTF8&qid=1216994566&sr=11-1]
Scenario: A retail sales application contains the classes Sale and DatabaseA. The Sale class represents a purchase transaction, and DatabaseA is the database backend it is stored in.
With only these two objects, the Sale class would need to contain the logic required to persist a sale to the database, which violates high cohesion. If DatabaseA were to change, the Sale class would also have to change. This violates low coupling [http://www.ibm.com/developerworks/rational/library/jun07/cuellar/].
If the database were to change to DatabaseB, an adapter would be required, as visualized in Figure 1:
[[Image:Wiki3A.jpg]]<br>
'''Figure 1'''
Instead, one could
[[Image:Wiki3B.jpg]]<br>
'''Figure 2'''
==Similar Patterns==
===Adapter===
This is similar to the Adapter pattern, except for a few key differences. The Adapter pattern applies when a new class is created to sit in the middle of to two existing classes that interact, such as in Figure 1. This does not decrease coupling or increase cohesion. Instead, the Broker class is part of the initial design, and the Sale never has to know how to interact with a database [2].
===Controllers in MVC===
In the [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model View Controller pattern], the Controller could be viewed as a Pure Fabrication, because it does not represent a concept in the problem domain. Instead, it is a layer that sits in between the Views and Models, allowing each to main high cohesion and low coupling [http://www.martinfowler.com/eaaDev/PassiveScreen.html]. MVC is such a common application of the Pure Fabrication principle that it has become its own design principle.


=References=
=References=
# Hayden, David. Over-Architecting Via Pure Fabrication and Indirection to Reduce Coupling. 26 Aug 2006. http://codebetter.com/blogs/david.hayden/archive/2006/08/26/Over_2D00_Architecting-Via-Pure-Fabrication-and-Indirection-to-Reduce-Coupling.aspx
# Hayden, David. Over-Architecting Via Pure Fabrication and Indirection to Reduce Coupling. 26 Aug 2006. http://codebetter.com/blogs/david.hayden/archive/2006/08/26/Over_2D00_Architecting-Via-Pure-Fabrication-and-Indirection-to-Reduce-Coupling.aspx
# Larman, Craig. ''Applying UML and Patterns: an Introduction to Object-oriented Analysis and Design and Iterative Development''. Upper Saddle River, NJ: Prentice Hall PTR, 2005. Print.
# Cuellar, Ezequiel. Performing use-case realizations: The case for high cohesion and low coupling. 15 Jun 2007. http://www.ibm.com/developerworks/rational/library/jun07/cuellar
# Fowler, Martin. Passive View. 18 July 2006. http://www.martinfowler.com/eaaDev/PassiveScreen.html
# Wikipedia. GRASP (object-oriented design). 18 October 2010. http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)
# Wikipedia. GRASP (object-oriented design). 18 October 2010. http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)
# Larman, Craig. ''Applying UML and Patterns: an Introduction to Object-oriented Analysis and Design and Iterative Development''. Upper Saddle River, NJ: Prentice Hall PTR, 2005. Print.

Revision as of 02:09, 2 December 2010

Overview

Pure Fabrication is a design pattern in which objects are created that do not correlate directly to real-world objects. This is generally used to achieve low cohesion and high coupling, as discussed in previous chapters. Although low cohesion and high coupling is an important design principle, fabricating objects that do not exist in the problem domain may lead to problems [1], thus classifying it as an anti-pattern.

Pure Fabrication

Pure Fabrication is a GRASP (General Responsibility Assignment Software Patterns) principle.

Examples

Larman provides an example of the Pure Fabrication pattern in his book Applying UML and Patterns. [2]

Scenario: A retail sales application contains the classes Sale and DatabaseA. The Sale class represents a purchase transaction, and DatabaseA is the database backend it is stored in.

With only these two objects, the Sale class would need to contain the logic required to persist a sale to the database, which violates high cohesion. If DatabaseA were to change, the Sale class would also have to change. This violates low coupling [3]. If the database were to change to DatabaseB, an adapter would be required, as visualized in Figure 1:


Figure 1

Instead, one could


Figure 2

Similar Patterns

Adapter

This is similar to the Adapter pattern, except for a few key differences. The Adapter pattern applies when a new class is created to sit in the middle of to two existing classes that interact, such as in Figure 1. This does not decrease coupling or increase cohesion. Instead, the Broker class is part of the initial design, and the Sale never has to know how to interact with a database [2].

Controllers in MVC

In the Model View Controller pattern, the Controller could be viewed as a Pure Fabrication, because it does not represent a concept in the problem domain. Instead, it is a layer that sits in between the Views and Models, allowing each to main high cohesion and low coupling [4]. MVC is such a common application of the Pure Fabrication principle that it has become its own design principle.

References

  1. Hayden, David. Over-Architecting Via Pure Fabrication and Indirection to Reduce Coupling. 26 Aug 2006. http://codebetter.com/blogs/david.hayden/archive/2006/08/26/Over_2D00_Architecting-Via-Pure-Fabrication-and-Indirection-to-Reduce-Coupling.aspx
  2. Larman, Craig. Applying UML and Patterns: an Introduction to Object-oriented Analysis and Design and Iterative Development. Upper Saddle River, NJ: Prentice Hall PTR, 2005. Print.
  3. Cuellar, Ezequiel. Performing use-case realizations: The case for high cohesion and low coupling. 15 Jun 2007. http://www.ibm.com/developerworks/rational/library/jun07/cuellar
  4. Fowler, Martin. Passive View. 18 July 2006. http://www.martinfowler.com/eaaDev/PassiveScreen.html
  5. Wikipedia. GRASP (object-oriented design). 18 October 2010. http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)