You are here: Re: the Visitor Design Pattern « PHP Programming Language « IT news, forums, messages
Re: the Visitor Design Pattern

Posted by Oli Filth on 10/26/59 11:33

Chung Leong wrote:
> Oli Filth wrote:
> > I think the OP has phrased this badly. He actually has an object
> > passing this ($this) to a method in another object, which is hardly
> > uncommon practice in most OO languages (e.g. registering a callback
> > interface with a child object).
>
> That's very different from object A calling a method of object B which
> in turns invokes methods on object A now isn't it? What the OP
> described

As I said, it's really not a great example (of something that's a good
idea in principle).

His example, which basically boils down to:

$book = new Book();
$plainVisitor = new PlainDescriptionVisitor();
$book->accept($plainVisitor);
$plainVisitor->getDescription();

has a pointless line $book->accept(), i.e. the Book is "doing" the
work.

$book = new Book();
PlainDescriptionVisitor::describe($book);

would have made much more sense, or if polymorphism of the visitors is
a concern:

$book = new Book();
$plainVisitor = new PlainDescriptionVisitor();
$plainVisitor->visit($book);
....
$plainVisitor->getDescription();

Either way, it avoids the $book->accept() call, which offers no
semantic value.

> can be more aptly called the prostitution design pattern.
> Object J has a need that it cannot satisfy, so it visits object H to
> get its private part operated upon. It's sick. It's immoral. Objects
> should only play around with their own thingies.

:)

--
Oli

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация