由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - question about Design Patterns
相关主题
C++问题,confusing...工厂模式 (转载)
C++: exception: out-of-order execution?问一下关于factory pattern对象的复制
问个disable copy constructor的问题builder pattern是一次性还是可复用好?
问一个constructor的问题 (转载)C++ 中 myobject * a =new myobject[n] 的问题
pthread_create inside a constructoroperator() overloading 一问
问个c++问题why do we still use dynamic allocation?
Is the order of initialization a, b, c or c, b, a?[合集] 一些C++问题
angular 2简直就是java嘛请教一个基本的constructor和destrcutor问题
相关话题的讨论汇总
话题: component话题: decorator话题: class话题: abstract话题: operation
进入Programming版参与讨论
1 (共1页)
s*****w
发帖数: 1527
1
the original standard sample is like this,
abstract class Component
{
public abstract void Operation();
}
class ConcreteComponent : Component
{
public override void Operation()
{
Console.WriteLine("ConcreteComponent.Operation()");
}
}
abstract class Decorator : Component
{
protected Component component;
....
}
b*****e
发帖数: 7
2
The Decorator constructor only needs to take a reference/pointer to
Component as parameter. It doesn't need to construct the Component. The
Component should have been already constructed when it is passed to
Decorator.
s*****w
发帖数: 1527
3
thanks for reply 1st,
my q is from this,
http://www.dofactory.com/Patterns/PatternDecorator.aspx#_self1
if class Component has a constructor taking 10 parameters,
how to make it work ?
as Decorator is asking for paramters now.

【在 b*****e 的大作中提到】
: The Decorator constructor only needs to take a reference/pointer to
: Component as parameter. It doesn't need to construct the Component. The
: Component should have been already constructed when it is passed to
: Decorator.

s*****w
发帖数: 1527
4
oops, u need to click the 1st code link,
sample code in C#
This structural code demonstrates the Decorator pattern which dynamically
adds extra functionality to an existing object.
Show code

【在 s*****w 的大作中提到】
: thanks for reply 1st,
: my q is from this,
: http://www.dofactory.com/Patterns/PatternDecorator.aspx#_self1
: if class Component has a constructor taking 10 parameters,
: how to make it work ?
: as Decorator is asking for paramters now.

b*****e
发帖数: 7
5
Both the C# samples take a component as iiput parameter.
First sample:
public void SetComponent(Component component)
or second sample:
public Decorator(LibraryItem libraryItem)
There is no need to construct the component in the decorator. By definition
a decorator adds additional behavior to the component *object*, not the
class. So a decorator should always reference the constructed component.
There is no need for a decorator constructor that constructs the component.

【在 s*****w 的大作中提到】
: oops, u need to click the 1st code link,
: sample code in C#
: This structural code demonstrates the Decorator pattern which dynamically
: adds extra functionality to an existing object.
: Show code

s*****w
发帖数: 1527
6
Hi Bayside,
i understand most of your replies, but in my case,
class Component has to take parameters for constructors,
so how can i change it ?
the only thing i can think of is constructor is just a dummy constructor,
but call a Component.init(parameters) afterwards.
how do you think ?

definition

【在 b*****e 的大作中提到】
: Both the C# samples take a component as iiput parameter.
: First sample:
: public void SetComponent(Component component)
: or second sample:
: public Decorator(LibraryItem libraryItem)
: There is no need to construct the component in the decorator. By definition
: a decorator adds additional behavior to the component *object*, not the
: class. So a decorator should always reference the constructed component.
: There is no need for a decorator constructor that constructs the component.

1 (共1页)
进入Programming版参与讨论
相关主题
请教一个基本的constructor和destrcutor问题pthread_create inside a constructor
question overloading ++ error问个c++问题
这个类的default constructor怎么写Is the order of initialization a, b, c or c, b, a?
c++ 里面 this pointer 是完全 un necessary 的吗?angular 2简直就是java嘛
C++问题,confusing...工厂模式 (转载)
C++: exception: out-of-order execution?问一下关于factory pattern对象的复制
问个disable copy constructor的问题builder pattern是一次性还是可复用好?
问一个constructor的问题 (转载)C++ 中 myobject * a =new myobject[n] 的问题
相关话题的讨论汇总
话题: component话题: decorator话题: class话题: abstract话题: operation