您的位置:首页 > 编程语言 > Java开发

设计模式--行为模式--Collecting Parameter--Java

2013-03-11 11:23 435 查看

Collecting Parameter

场景

You have a single bulky method that accumulates information to a local variable.

你有一个较长方法,其主要为了积累局部信息。

定义

A Collecting Parameter is an object that you pass to methods in order to collect information from those methods. This pattern is often coupled with Composed Method

Collecting parameter Patterns 是通过将Collecting Parameter对象以参数形式传入到所涉及的方法中去收集信息。通常此模式会和Composed Method 偶合在一起。

A Collecting Parameter may also be passed to methods on multiple objects

Collecting Parameter 对象可以传递到不同类中的方法中。

引自《Refactoring to Patterns》中的例子:



优点

Helps transform bulky methods into smaller, simpler, z methods.  有助于将杂乱的方法编程一些小的简单的方法。

Can make resulting code run faster.                                                       可以使生成结果信息的代码执行更快。

引自JUnit 中的例子:







内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息