Designing loosely coupled components with GTKs event model
This is a fairly vague and open e开发者_StackOverflownded question, but hopefully someone can still provide some insight.
I am using GTK (through Gtk2Hs with Haskell via GHC) and I am wondering if there is any general advice for handling events. I am used to keeping system components loosely coupled (from OO practice) and this extends to the event model. I want to know if there any patterns of design that can be used to handle/re-fire/propogate events etc. in both Gtk or Haskell that keeps the inter-module/function dependency low.
Thanks.
GTK+ events are identified by strings (in the core GTK+ library, at least). There should be no coupling at all. At least when using the C API, it's perfectly possible to e.g. write programs that try to emit events that are not, in fact, supported by any widgets. Since the event is only identified by a string, the compiler doesn't help guard against this.
精彩评论