in reply to Builder design pattern with lots of parameters - trying to declutter design
Here are some “thoughts purely of my own” which come to my mind immediately when I read this ... and, mind you, I’m using my own made-up (I hope, common-sense) terminology. Please don’t flip through design-pattern textbooks trying to figure out which one of those I am referring to. This is coming from my own cranium.
It may be that you are exposing all of those attributes so that different other actors can make appropriate decisions using them. The problem here is that every actor you meet has to be familiar with every product it may meet, either now or in the future. Likewise, when new actors are invented, the logic which deals with “all those attributes” must be duplicated into them. Pretty soon you have exactly the web of interdependency that you would like to avoid, even though it has been couched in the latest trendy metaphors.
Having spent a few seconds now groping for an analogy ... For that purpose, I like to coin the notion of what I shall call an “apprentice.” An apprentice is the fellow who tags along beside the master in the shop, helping the master out and in the process learning his trade. The apprentice is also, quite admittedly, the “grunt.” Well, in this case, apprentices are the folks who can answer a product’s specific questions about a builder, and a builder’s specific questions about a product, and who are able to determine whether they actually possess the knowledge necessary to speak-up in the first place. There might be any number of these, and when there is a need to get an actor and a product together, we have to find the apprentice that is most knowledgeable – who is the “best fit.”
An apprentice, interviewing for the job as it were, might ask of the product, “do you have parameters X, Y, Z?” And of the actor, “do you need to know A, B, C?” Pause. “Then I can help you, and my fitness score is 21.”
The purpose of the apprentice is to answer questions, and to do grunt work. An arbitrary number of them can exist and perhaps more than one of them are participating at any time. The complexity of this so-to-speak “cartesian join” is now wrapped-up in the implementation of the apprentice, and of the apprentice-selection heuristic.
I do not intend to suggest that “apprentice” is the best word to use here. I didn’t read it in a book; I just now made it up. In fact it really isn’t the best word or the best analogy. The notion is basically that of a “plug-in, hot-swappable software subject-matter expert,” who enables the system to be flexible more-or-less “by committee.” If a VehicleBuilder or even a VehicleBuyer needs to know the answer, they don’t have to have the logic to determine the answer themselves ... they just have to find someone who knows is the most confident that he has the answer, and then ask him to produce it. I think that the germ of the idea is a sound one, and I do not proclaim it to be original. (And if it does happen to be original, you will not be asked to buy my book nor to attend my seminar anytime soon.)
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Builder design pattern with lots of parameters - trying to declutter design
by tospo (Hermit) on Mar 28, 2011 at 16:25 UTC | |
by locked_user sundialsvc4 (Abbot) on Mar 28, 2011 at 17:39 UTC |