CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

Uncle Bob Martin on the Visitor Pattern

Some design patterns just appear weird the first time you come across them.  The "Visitor" pattern is like that for me because of all the double dispatch stuff.  I understand it and I use it on rare occasions, but I rarely reach for it because I'm not perfectly comfortable with it.  Uncle Bob of ObjectMentor has a great post on the Visitor pattern called "I Use Visitor" that's a good explanation of the pattern.  Familiarity with a pattern like Visitor mitigates the weirdness.

It's timely for me because I have a little side project going that will likely involve a "Composite" pattern that will include multiple operations across the aggregate object graph.  I'll definitely consider a Visitor when I get there.

I used to grade code submissions from job applicants at a former employer.  One of the very few good submissions I ever looked at came from a C# coder who used a Visitor pattern on a sales tax calculation problem (think lot's of exception cases).  At first blush I thought it was over-designed, but after a closer look I thought the usage of the Visitor pattern was a fairly elegant way to solve the problem.



Comments

c pound said:

# September 28, 2005 11:32 AM

c pound said:

# September 28, 2005 11:35 AM

Chaitanya said:

Hi

I have recently been approached by thoughtworks regarding a job opening.

Can you give me some pointers for sales tax programming problem that the give for the code review ?

any help in this regard would be appreciated by me.

thanks

# July 17, 2007 1:24 PM

Jeremy D. Miller said:

Um, no.  I'll give you one little hint:  polymorphic arrays and branching logic.

# July 17, 2007 2:12 PM

Chaitanya said:

thanks jeremy, i will try to work it out

# July 18, 2007 12:32 PM

Chaitanya said:

Hi Jeremy

I cleared the first round , now waiting for the second

# July 27, 2007 10:22 PM

OS said:

Chaitanya,

Can you please share your solution with me?

# December 3, 2007 12:58 AM

Niki said:

I sent the solution for same problem but could not get through the first round. Chaitanya can you share your solution with me.

# June 6, 2008 10:26 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP