Specs (Both kinds)

Specifications (noun, plural)

1. A set of requirements defining an exact description of an object or a process.
2. In computer programming, a Design Pattern where business logic can be recombined by chaining the business logic together using Boolean logic.

Part of almost every development life cycle is the design stage. This is where you determine the requirements of the application, if its feasible, and if so: a) how to implement it and b) how to test if the implementation works. An analogy: If an application is a house, one of the first things to determine is the number of rooms & floors, which materials to use, etc. Specifications are the documents that is produced after the design stage, which is basically the blueprint of the house.

Many programmers skip the design stage, opting to code directly. Big Mistake. That’s like building a house without any documents: no blueprint, no materials manifest, etc. Sure, it might work but only after a lot of trial and error (basically, the failed apps becomes your documents). And even if it does work, who in their right minds would live in that house? Without specs, its hard to test if works or not.

The specifications design patter, on the other hand, is quite different. Sometimes, business logic objects can be “chained” together like so:

ISpecification CardsToPrint = Red.And(Even.Not()).And(Facecard); 
ISpecification CardsToPrint = Even.And(Red.Not()).Or(Facecard); 
ISpecification CardsToPrint = Facecard.Or(Even.Not());
Design Pattern: Specification Patten
Pattern Type: Behavioral
First Stated in: http://www.martinfowler.com/apsupp/spec.pdf
Description: Recombinable business logic in a boolean fashion

My sample app uses a standard deck cards, then uses the Specification pattern to specify which cards to print. Of course, one can easily substitute “Employees” or “Places” with the collection of cards. Feel free to experiment with the CardsToPrint variable: to check the results quicker, comment out the shuffle method.

Source Files (in C# 4.0): SpecificationsPatternExample_Source.zip

Specifications: A couple of important computer science topics that has the same name but different meanings~

0 comments:

Post a Comment