Pattern of the week: Specification Pattern

January 19, 2012 by · Leave a Comment
Filed under: Architecture, Design, Patterns 

This weeks pattern is the Specification Pattern. We will spend this week reviewing this pattern, how it is used and what its intent is for. For some more in-depth definition you can see here and Here are some useful descriptions, but to appreciate this we will review the intent and possible solutions and applications for this pattern in everyday work.

Here is the intent of the Specification pattern: “ to separate the logic for (e.g.) filtering an entity from the entity itself.”

Specification_UML

 

Example application for this pattern has been to support filtering as a pluggable entity “collection” of specifications.  The implementation details as things mature are apparent with generics and expression tree’s and event the IQueryable<> interfaces against OR/M layers.

The main benefits of this pattern are

1 – Loose coupling of the filter logic from the objects being filtered,

2- Single responsibility: Filtering is essentially a first class citizen and also can exist in a decoupled state for better testing and independent improvement

3 – Composition of specifications allows for reuse and complex nested specifications for easier maintenance.

Pattern of the week: Memento

January 14, 2012 by · Leave a Comment
Filed under: Architecture, Design, Patterns, Programming 

This weeks pattern is the Memento Pattern. We will spend this week reviewing this pattern, how it is used and what its intent is for. For some more in-depth definition you can see  here and here are some useful descriptions, but to appreciate this we will review the intent and possible solutions and applications for this pattern in everyday work.

Here is the intent of the Memento pattern: “Without violating encapsulation, capture and externalize an object’s internal state so that the object can be returned to this state later.  A Magic cookie encapsulating check point capability, promote undo or rollback to full object status.”

 

memento

Example application for this pattern has been to support undo or rollback, other common implementations are a finite state machine.  In my own personal development projects I have used memento pattern to create and audit trail with full play-back of the payloads as an encapsulation exercise. 

Pattern of the week: Flyweight

January 6, 2012 by · Leave a Comment
Filed under: Architecture, Design, Patterns 

This weeks pattern is the FlyWeight Pattern. We will spend this week reviewing this pattern, how it is used and what its intent is for. For some more indepth definition you can seeandare some usful descriptions, but to appriciate this we will review the intent and possible solutions and applications for this pattern in everyday work.

Here is the intent of the flyweight pattern: “The intent of this pattern is to use sharing to support a large number of objects that have part of their internal state in common where the other part of state can vary.”

 

Flyweight UML Diagram

Example application for this pattern has been a text editor abstracting out the state of each character as glyphs.  This is a nice concept but really limits the true application for this pattern across the board.  When I see this pattern I think caching and this is also very similar to a connection pooling type of resource manager.  I think the big difference here is these share some state while other parts are unique making each type a potential hybrid.  This week in exploring this pattern think about applications for it.  What interesting applications can you think of for this pattern, it seems with the advent of large memory and fast processors this hasn’t been considered except in memory condious applications with limited resources.