Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

Syndication

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.


Posted Tue, Sep 27 2005 1:26 PM by Jeremy D. Miller
Filed under:

[Advertisement]

Comments

c pound wrote Just stopping by
on Wed, Sep 28 2005 11:32 AM
c pound wrote Just stopping by
on Wed, Sep 28 2005 11:35 AM
Chaitanya wrote re: Uncle Bob Martin on the Visitor Pattern
on Tue, Jul 17 2007 1:24 PM

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

Jeremy D. Miller wrote re: Uncle Bob Martin on the Visitor Pattern
on Tue, Jul 17 2007 2:12 PM

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

Chaitanya wrote re: Uncle Bob Martin on the Visitor Pattern
on Wed, Jul 18 2007 12:32 PM

thanks jeremy, i will try to work it out

Chaitanya wrote re: Uncle Bob Martin on the Visitor Pattern
on Fri, Jul 27 2007 10:22 PM

Hi Jeremy

I cleared the first round , now waiting for the second

OS wrote re: Uncle Bob Martin on the Visitor Pattern
on Mon, Dec 3 2007 12:58 AM

Chaitanya,

Can you please share your solution with me?

Niki wrote re: Uncle Bob Martin on the Visitor Pattern
on Fri, Jun 6 2008 10:26 PM

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

Add a Comment

(required)  
(optional)
(required)  
Remember Me?