Re: When and where to use Visitor Pattern?
- From: "Daniel Parker" <danielaparker@xxxxxxxxxxx>
- Date: 28 Apr 2005 12:46:35 -0700
Robert C. Martin wrote:
> On Wed, 27 Apr 2005 00:51:29 -0400, "Daniel Parker"
> <danielaparker@spam?nothanks.windupbird.com> wrote:
>
> >wouldn't "instanceof" do just as well? And be a little
> >clearer? With less clutter in the core class (no visit method)?
>
>
> if (x instanceof D1)...
> else if (x instanceof D2)...
> else if (x instanceof D3)...
> ...
> No, instanceof does not do just as well. To use instanceof you have
> to create a if/else statement that depends on every possible
> derivative:
Well, no, you need to query for the interfaces of interest. In most
cases that wouldn't be every possible derivative, it would be a small
number of interfaces that every possible derivative implements. But
lets say you do, take the modem example in your article...
>
> Not only is this time consuming, it's also heavy with dependencies.
> visitor (especially acylic visitor) mitigates both of these problems.
>
I don't see it. Your UnixModemConfigurator has to implement visit
methods for all the derivatives of interest, much as instanceof has to
query for the derivatives of interest. There doesn't seem to be a
fundumental difference here. The main difference is the additional
level of indirection required by Visitor, and the need to adorn the
Modem class with a superfluous accept method. Occam's Razor, it seems
to me, would suggest removing these.
Regards,
Daniel Parker
.
- Follow-Ups:
- Re: When and where to use Visitor Pattern?
- From: Robert C . Martin
- Re: When and where to use Visitor Pattern?
- References:
- When and where to use Visitor Pattern?
- From: Sam Hwang
- Re: When and where to use Visitor Pattern?
- From: Ilja Preuß
- Re: When and where to use Visitor Pattern?
- From: Rich MacDonald
- Re: When and where to use Visitor Pattern?
- From: Daniel Parker
- Re: When and where to use Visitor Pattern?
- From: Robert C . Martin
- When and where to use Visitor Pattern?
- Prev by Date: Re: Lahman, how ya doing?
- Next by Date: Re: When and where to use Visitor Pattern?
- Previous by thread: Re: When and where to use Visitor Pattern?
- Next by thread: Re: When and where to use Visitor Pattern?
- Index(es):