about listeners 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);
}

你可能感兴趣的:(about listeners idea)