 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Hubert Anemaat Guest
|
Posted: Wed Dec 08, 2004 11:21 am Post subject: Difference Builder and Strategy pattern |
|
|
Hello,
What is the difference between Builder and Strategy pattern ? I read that
Builder is a creation pattern and Strategy is a behavior pattern.
The UML diagrams look the same for me.
Are objects creating a bar diagram or a circle diagram from data a Builder
pattern or a Strategy pattern ?
Thanks,
Hubert Anemaat
|
|
| Back to top |
|
 |
Peter Morris [Air Softwar Guest
|
Posted: Wed Dec 08, 2004 11:51 am Post subject: Re: Difference Builder and Strategy pattern |
|
|
A builder will create something for you, whereas a Strategy is more like a
virtual/abstract method.
For example, if you wanted to release an application for charging customers
for shipping goods, but the rules for each customer were so specific that
you could never introduce anything generic you would use a strategy. You'd
problem declare an interface, and have DLLs in the EXE folder. Each
customer would have a setting "Tariff calculator name" = "Basic.dll", the
DLL would be loaded, the ITariffCalculator extracted, and then used to
calculate charges for that customer.
You certainly wouldn't want to re-release the app each time you had a new
customer.
--
Pete
====
Audio compression components, DIB graphics controls, FastStrings
http://www.droopyeyes.com
Read or write articles on just about anything
http://www.HowToDoThings.com
My blog
http://blogs.slcdug.org/petermorris/
|
|
| Back to top |
|
 |
Jim Cooper Guest
|
Posted: Wed Dec 08, 2004 12:49 pm Post subject: Re: Difference Builder and Strategy pattern |
|
|
They are similar.
In general though, Strategy is used where you want to apply different
algorithms to do the same thing. The classic example is wage vs salary
employees - you need different calculations to get the monthly pay for
each. By putting the pay calculations in another class than the employee
class you also allow changing employee's status. Typically the pay will
be surfaced in the employee class though.
Builder is somewhat different in that the end product is a complex
object that is made of objects of a different class than the algorithm
in charge of creating that complex object. Often that complex object is
a quite different type at different times (and is often a Composite).
Cheers,
Jim Cooper
_______________________________________________
Jim Cooper [email]jim (AT) falafelsoft (DOT) com[/email]
Falafel Software http://www.falafelsoft.com
_______________________________________________
|
|
| Back to top |
|
 |
Jim Cooper Guest
|
Posted: Wed Dec 08, 2004 1:21 pm Post subject: Re: Difference Builder and Strategy pattern |
|
|
It strikes me I may not have been that clear :-)
A simple explanation is Strategy is different ways to do the same thing,
whereas Builder is the same way to build different things :-)
For example, I need to parse a text representation to generate a complex
set of objects (customers, products etc). So I'm going to use Builder to
do that. I have 3 sets of objects, a reader, a set of builders, and the
customers,products etc.
Now suppose I later want to parse an XML file and build the customers,
products etc structure. I will need a different reader and set of
builders. What I might do is use Strategy to determine which
reader/builder set to use in which situation.
Cheers,
Jim Cooper
_______________________________________________
Jim Cooper [email]jim (AT) falafelsoft (DOT) com[/email]
Falafel Software http://www.falafelsoft.com
_______________________________________________
|
|
| Back to top |
|
 |
Charles McAllister Guest
|
Posted: Wed Dec 08, 2004 3:13 pm Post subject: Re: Difference Builder and Strategy pattern |
|
|
Hubert Anemaat wrote:
| Quote: | Hello,
What is the difference between Builder and Strategy pattern ? I read that
Builder is a creation pattern and Strategy is a behavior pattern.
The UML diagrams look the same for me.
Are objects creating a bar diagram or a circle diagram from data a Builder
pattern or a Strategy pattern ?
Hi Hubert. See the thread "name this pattern game" on 10/21 in this |
group for examples on the strategy pattern. HTH.
|
|
| Back to top |
|
 |
Gerrit Beuze Guest
|
Posted: Thu Dec 09, 2004 7:26 am Post subject: Re: Difference Builder and Strategy pattern |
|
|
Hi Hubert,
In addition to what other already said:
| Quote: | The UML diagrams look the same for me.
|
That is the case with many patterns: the structure
(inheritance, uses relations) might be identical but the difference
is in their intention.
Have a look at Proxy and Adapater: very similar.
| Quote: | Are objects creating a bar diagram or a circle diagram from data a Builder
pattern or a Strategy pattern ?
|
That depends:
If the client creates the abstracted diagram like this
// builder usually does not require backpointer?
// as it's fed with everything it needs.
Builder := TCircleDiagram.Create;
Builder.StartDiagram();
Builder.AddElement(10%, 'A");
Builder.AddElement(15%, 'B");
Builder.AddElement(9%, 'C");
etc. etc
Builder.AddTitle('bla');
Builder.AddAxis('X', [0,100]);
etc.
Builder.EndDiagram();
You're typiclaly using a builder. The client provides
the elements / data in a fixed way. The builder determines how & which
diagram is build.
If you're using a strategy, it's usually a few methods you call,
// strategy usually uses back pointer or Memento to
// fetch the data and do what it should do.
Strategy := TCircleDiagram.Create(Self, Memento);
Strategy.Execute;
Strategy.Free;
Gerrit Beuze
ModelMaker Tools
|
|
| Back to top |
|
 |
Hubert Anemaat Guest
|
Posted: Thu Dec 09, 2004 10:55 pm Post subject: Re: Difference Builder and Strategy pattern |
|
|
Thank you all for the information !
Hubert Anemaat
"Hubert Anemaat" <hubert (AT) anemaat (DOT) nl> schreef in bericht
news:41b6e32c$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hello,
What is the difference between Builder and Strategy pattern ? I read that
Builder is a creation pattern and Strategy is a behavior pattern.
The UML diagrams look the same for me.
Are objects creating a bar diagram or a circle diagram from data a Builder
pattern or a Strategy pattern ?
Thanks,
Hubert Anemaat
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|