Pure Fabrication GRASP Pattern - Software Design Patterns and Principles - Applying UML and Patterns - Domain-Driven Design

Pure Fabrication is one of the nine GRASP Patterns that help aid developers in assigning responsibilities to objects in your web applications and winform applications.  These nine GRASP Patterns are found in Craig Larman's excellent book, Applying UML and Patterns, An Introduction to Object-Oriented Analysis and Design and Iterative Development.  I have talked about a number of these GRASP Patterns already, which you can find at the end of the article.

 

Pure Fabrication GRASP Pattern

The Pure Fabrication GRASP Pattern is a strategy to introduce objects in your domain model that are not related to the problem domain ( fabricated ), but help keep cohesion high and coupling low in your overall application.  You can essentially think of these objects as helper objects that allow your application to be more pluggable as well as allow you to use more of your code ( code re-use ) in other applications.

 

Domain-Driven Design - Repositories

An example of an object introduced in a domain model that follows the Pure Fabrication GRASP Pattern and supports High Cohesion and Low Coupling is the Repository Object in Domain-Driven Design.

A repository in Domain-Driven Design supports high cohesion by centralizing all the data reconstitution and persistence logic for aggregate domain objects.  This way the domain objects don't have to bother themselves with behaviors that deal with persistence behavior for data storage. The domain object becomes merely a container of data and behaviors associated with that data.

In the same respect, the repository supports low coupling by hiding the method of persistent storage from the domain model and upper layers.  The repository offers a buffer from the actual persistent medium, which means the domain model can be freely used ( code re-use ) no matter if the storage is a database, xml files, in-memory, etc.

 

Factories

Factories are fabricated objects that are also added to a domain model to support high cohesion and low coupling with respect to the Pure Fabrication GRASP Pattern.

Often the creation of an object is complex.  In the case of Domain-Driven Design where only aggregate objects are created or reconstituted by the repository, the creation of the aggregate object often spawns the creation of child objects.  For example, the creation of an Order object can cause the creation of order line items, payments, customer information, etc.

When object creation is complex, time consuming, memory intensive, etc., the creation of these objects are typically handed off to a class factory, which can be as simple as a factory method.  This focuses ( cohesion ) the burden of creating these complex objects into a specialized class and away from a class constructor, which as a rule of thumb should be simple.  Again, this leaves the domain object to data and behavior on the data and not to complex creation of it and child objects.

 

Conclusion

The Pure Fabrication GRASP Pattern essentially condones adding certain classes into your application domain layer to create high cohesion and low coupling as well as allow better code re-use from application to application.  In Domain-Driven Design, you can find two such classes, Repositories and Factories, to help with object persistence and object creation, respectively.  Repositories and factories delegate object reconstitution and creation to specialized classes so domain objects are mere data containers and behaviors that act on that data.

 

GRASP Patterns

I have talked about several other GRASP Patterns introduced in the book, Applying UML and Patterns, An Introduction to Object-Oriented Analysis and Design and Iterative Development.  I will be talking about those yet to be covered in the following weeks.

  • Information Expert ( Part I and Part II ) - A general principal of object design and responsibility assignment?
  • Creator - Who creates?
  • Controller - What first object beyond the UI layer receives and coordinates a system operation?
  • Low Coupling - How to reduce the impact of change?
  • High Cohesion - How to keep objects focused, understandable, and manageable?
  • Polymorphism - Who is responsible when behavior varies by type?
  • Pure Fabrication - Who is responsible when you are desperate, and do not want to violate high cohesion and low coupling?
  • Indirection - How to assign responsibilities to avoid direct coupling?
  • Protected Variations - How to assign responsibilities so that the variations or instability in the elements do not have an undesirable impact on other elements?

 

Agile Software Development, Principles Patterns and Practices

The GRASP Patterns are similar to Object-Oriented Principles that are associated with class design as discussed by Robert Martin.  See my chapter by chapter review of Agile Software Development, Principles Patterns and Practices by Robert Martin.

 

David Hayden ( Website / Blog )

DrinkingGyokuro Green Tea

 

posted on Sunday, September 18, 2005 2:15 PM

Main

David Hayden Google +

David Hayden Twitter

Health & Fitness

JavaScript Patterns Book Review

HTML 5 and CSS3 - Develop with Tomorrow's Standards Today

Professional ASP.NET Design Patterns Book Review

Beginning Mac Programming Book Review

C# in Depth Book Review

ASP.NET MVC

Orchard CMS

Categories