Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Visitor vs. Strategy pattern (subtle difference?)

 
Marcos Urata
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am preparing for the OOAD exam and I just can�t see why would one use the visitor pattern instead of the strategy pattern.

As far as I understand, both allows to change the implementation class at runtime. So, what is the subtle difference between them?

Maybe on the visitor pattern, maintainance can be a problem if it is necessary to add new classes that also needed to be visited, since it would mean to add a new method on all the classes that implement the Visitor interface?

Thanks
Marcos
 
Baiju Varugese
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Visitor

The intent of the visitor pattern is to add operations to a class which has rich data structure. If we are not able to identfiy all the operations in for the class but we expect in future we may need to add method for the class, but it is not advisible to alter the class, so to be on safer side we can put a visitor and share the data to the visitor class

Strategy

The intent of steategy patten is to define a family of algorithm, encapsulate each one, and make them interchangeable. Lets the algorithm vary independently from the clients that use it. this pattern is used to add different algorithm nothing to do with the data in the class

hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic