sanshaoye
发贴: 16
积分: 0
|
于 2004-11-19 12:16
I don't think so.
The first,consider the purpose of those two pattern
The Composite Design pattern allows a client object to treat both single components and collections of components identically.
If you read the junit code, you can found TestSuite composite a collections of TestCase,they implements the common interface Test,so you can treat TestSuite and TestCase identically.If you run a TestSuite will run all TestCase of that include.
The Decorator Pattern is used for adding additional functionality to a particular object as opposed to a class of objects.
Consider,we will and some function for your class exist already. It is easy to add functionality to an entire class of objects by subclassing an object, but it is impossible to extend a single object this way. With the Decorator Pattern, you can add functionality to a single object and leave others like it unmodified.
Nothing is impossible to a willing heart!
|