Updated: 4/23/2003; 11:27:00 AM.
Brian Maso's Tecno-Geek Weblog
The musings of a mild-mannered tecno-geek.
        

Wednesday, March 05, 2003

Either shrewed or just stupid and audacious. Not sure which. Its like patenting the idea of scratching your nose. (Note to self: get a patent on scratching nose. Call it "nasal scarification".)
8:51:09 PM    comment []

So if really basic construction concepts like Delegation, Recursion and State Machine are "Design Patterns", shouldn't Creation/Allocation also be?

One object (call it the "master") needs another (call it the "slave") to complete an operation. The "master" needs a "new" object, initialized to a known state, and the master needs exclusive access so the "slave" doesn't undergo asynchronous state changes.

The master creates or allocates the object. There are a few current "Design Patterns" that all support this "master-creates-slave" functionality. They really shouldn't be patterns -- they are merely implementations of the same pattern. Those common patterns are:

  • Creator/Constructor
  • Factory
  • Abstract Factory
  • Object Pool

When modeling from a high enough level, these patterns all look the same. Whether or not an implementation uses a constructor, a factory or a pool is generally a performance choice. And the same "master-creates-slave" relationship can be implemented using any of them. In fact, you can easily refactor code that employs any one of these patterns to employ any one of the others pretty easily.

I would argue these four patterns are in fact allotropes of a single, unifying pattern called Allocation. Now I know the world doesn't need yet another pattern, but in this case I'm actually proposing we get rid of 4 and replace them with a single one.

Update: Don Box comments "Actually, I think if you add the 'Indirection' pattern, you could subsume the remaining 19 patterns from GoF :-)".

With "Allocation" I'm thinking about Ambler's Agile Modeling, and the practice of Applying Patterns Gently. (See later blog entry.) When in the course of modeling and design I have one object (or component) creating another, from a certain level of abstraction I don't really care how I'm creating the other object: using a factory, using a constructor, or allocating from a pool. Those decisions are lower level, and ideally the design should allow you to switch between them fairly agilely.

There is no adequately high level of abstraction that would allow you to collapse all the design patterns together and enjoy any process efficiency.


11:07:29 AM    comment []

© Copyright 2003 Brian Maso.
 
March 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Feb   Apr


Click here to visit the Radio UserLand website.

Subscribe to "Brian Maso's Tecno-Geek Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.