tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

about listeners idea

Posted on 2011-05-24 13:10 Tommy Liang 阅读(215) 评论(0)  编辑 收藏 引用 所属分类: development idea
think about the grid listeners of grid, it's so complicate that it's hard to maintain relationship  and status,I think it's necessary to arose an intermediate level to cope with this;
perhaps like this:

//somewhere in A.hpp ...
Grid A("guid_a");
//somewhere else in B.hpp
Grid B("guid_b");
//somewhere else in C.hpp
Form c("guid_c");

A.AddListener("guid_b");      //why use string but not directly object pointer? because perhaps listeners is not yet valid at this runtime, this is just a registeration work
A.AddListener("guid_c");

//cope with the code when A select a row:
GridListenerHandler handler(A);
handler.HandleListeners();

//how to handle? like follow:
Context context = ...;
BOOST_FOREACH(shared_ptr<IListener> listener, InnerGetListeners())
{
       listener->Execute(context);
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理