• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Factory Pattern and Strategy Pattern.

 
Zhou Can
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between Factory Pattern and Strategy Pattern ?
They are much like each other in outline.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you could think of the Abstract Factory Pattern as the Strategy Pattern applied to Factory Method...
I don't have the GoF book at hand, though...
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The two patterns are nothing alike either in intent or in implementation. What were you reading that convinced you they're the same?
Kyle
[ September 13, 2002: Message edited by: Kyle Brown ]
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wellcome to the Ranch ZhouCan.
Please read our naming policy and change your displayed name accordingly.
The goal of the Factory pattern is to isolate the creation of an intance from the code that is using that instance.
The goal of Strategy is to be able to try several algorithms/policies to resolve a problem/situation.
[ September 14, 2002: Message edited by: Jose Botella ]
 
Andy Jackson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you think about it the Abstract factory is a structural pattern allowing different but related objects to be constructed - that's all.
The strategy pattern is behavioural and all the objects created exhibit different behaviours (or strategies - hence the name) for dealing with the problem.
Andy
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic