访客设计模式 [英] the Visitor Design Pattern

查看:70
本文介绍了访客设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2005年11月28日新增的 www.FluffyCat.com PHP 5设计模式

示例 - 访问者模式。


在访问者模式中,一个类调用另一个类中的函数

并传递一个实例本身。被叫类对每个可以调用它的类都有特殊的

函数。


使用访问者模式,调用类可以有新的操作
添加
而不会自行更改。

http://www.fluffycat.com/SDCMSv2/PHP...terns-Visitor/

解决方案



FluffyCat写道:

2005年11月28日新增 www.FluffyCat.com PHP 5设计模式
示例 - 访问者模式。

在访问者模式中,一个类在另一个类中调用一个函数
并传递一个自己的实例。被调用的类具有可以调用它的每个类的特殊功能。

使用访问者模式,调用类可以添加新操作而不会自行更改。 />
http://www.fluffycat .com / SDCMSv2 / PHP ... terns-Visitor /




将自身实例传递给另一个类的类意味着你

不要害怕知道你在做什么。下一步是什么?意大利面

设计模式?


Chung Leong写道:

FluffyCat写道:

2005年11月28日新增 www.FluffyCat.com PHP 5设计模式
示例 - 访问者模式。

在访问者模式中,一个类调用另一个类中的函数
并传递其自身的实例。被调用的类具有可以调用它的每个类的特殊功能。

使用访问者模式,调用类可以添加新操作而不会自行更改。 />
http://www.fluffycat .com / SDCMSv2 / PHP ... terns-Visitor /



将自己的实例传递给另一个类的类意味着你不要吓得知道你在做什么。下一步是什么?意大利面的设计模式?




我认为OP的表达非常糟糕。他实际上有一个对象

将这个(


this)传递给另一个对象中的方法,这几乎不是什么?b $ b不常见的做法大多数OO语言(例如注册回调

与子对象的接口)。


然而,OP的例子不是特别好,因为它从所讨论的对象外面驱逐了所有的




-

Oli


New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern
Examples - the Visitor Pattern.

In the Visitor pattern, one class calls a function in another class
and passes an instance of itself. The called class has special
functions for each class that can call it.

With the visitor pattern, the calling class can have new operations
added without being changed itself.

http://www.fluffycat.com/SDCMSv2/PHP...terns-Visitor/

解决方案


FluffyCat wrote:

New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern
Examples - the Visitor Pattern.

In the Visitor pattern, one class calls a function in another class
and passes an instance of itself. The called class has special
functions for each class that can call it.

With the visitor pattern, the calling class can have new operations
added without being changed itself.

http://www.fluffycat.com/SDCMSv2/PHP...terns-Visitor/



A class that passes an instance of itself to another class means you
don''t freaking know what you''re doing. What''s next? The spaghetti
design pattern?


Chung Leong wrote:

FluffyCat wrote:

New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern
Examples - the Visitor Pattern.

In the Visitor pattern, one class calls a function in another class
and passes an instance of itself. The called class has special
functions for each class that can call it.

With the visitor pattern, the calling class can have new operations
added without being changed itself.

http://www.fluffycat.com/SDCMSv2/PHP...terns-Visitor/



A class that passes an instance of itself to another class means you
don''t freaking know what you''re doing. What''s next? The spaghetti
design pattern?



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).

However, the OP''s example is not particularly great, as it''s all being
driven from outside the objects in question.

--
Oli


这篇关于访客设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆