会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
mrfangzheng
Hope and fear are useless. Be confident, and always be prepared for the worst.
首页
::
新随笔
::
联系
::
管理
编程要素
Posted on
2008-04-22 11:01
mrfangzheng
阅读(
185
) 评论(
0
)
收藏
举报
Interface, Event, Wrapper
Code
//
an interface
public
interface
IOperator
{
event
EventHandler OperationCompleted;
void
Operate();
}
//
a base implementation
public
class
OperatorBase : IOperator
{
public
event
EventHandler OperationCompleted;
public
virtual
void
Operate()
{
throw
new
Exception(
"
Not implemented
"
);
}
protected
virtual
void
OnOperationCompleted(EventArgs e)
{
if
(
this
.OperationCompleted)
{
this
.OperationCompleted(
this
, e);
}
}
}
//
a wrapper base
public
class
OperatorWrapperBase : IOperator
{
IOperator mWrappee;
public
OperatorWrapperBase(IOperator wrappee)
{
this
.mWrappee
=
wrappee;
}
public
IOperator Wrappee
{
get
{
return
mWrappee;}
}
public
virtual
void
Operate()
{
this
.Wrappee.Operate();
}
public
event
EventHandler OperationCompleted
{
add
{
this
.Wrappee.OperationCompleted
+=
value; }
remove
{
this
.Wrappee.OperationCompleted
-=
value; }
}
}
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3