Re: Design decision for a game
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 22 May 2008 18:38:22 -0700
On Thu, 22 May 2008 17:44:58 -0700, Tom Anderson <twic@xxxxxxxxxxxxxxx> wrote:
On Thu, 22 May 2008, Peter Duniho wrote:
I think ultimately I'd go with _some_ variation on this last approach (that is, the one where the Rule supports listeners for events separated into appropriate categories, whether in the same interface or in two or more), but any of the above would probably work (including what you posted, if you really want to do it that way).
I'm thinking having a list of listeners on each Rule is overkill - are there ever cases where you'd want to listen to one Rule but not others?
Hard to say. I'm not the OP and so it's difficult for me to comment what must or must not be characteristic of his ultimate implementation. But I'm not sure I see much of a downside. Especially if the Rule implementations all share a common implementation, where the actual listener list is maintained (inasmuch as duplicated implementations is at least part of the potential redundancy here, that would be addressed in that way).
Alternatively, if there are to be different listener interfaces for each Rule (in addition to some base interface, presumably from which each of the specific Rule interfaces inherit), then obviously each Rule instance would have different listener interfaces subscribed (even if they are all implemented by the same object). Depending on what notifications are required and whether there's a good way to generalize them so that a single RuleListener interface can apply to all Rule implementations, this may also argue in favor of per-Rule listener lists.
We don't really know enough about the larger problem to know whether this latter design requirement applies. (Or, at least, I don't...maybe you know more about this particular card game).
How about putting the listeners on the House, and having the rule call a method on the House which gets it to dispatch the event? You might even want the listeners to be on the Game object.
I don't see anything wrong with that per se. It's just that we don't have enough real information about the game and the intended implementation to know for sure if that's appropriate. I also think that even if it's overkill, conceptually it makes more sense to me for a Rule to implement the RuleListener list.
If there was some concern that multiple objects would wind up all subscribing to the same large set of Rule instances, one could implement a delegation scheme, in which the House or Engine (to use the OP's name for what I called "Game") also maintains a list of RuleListeners to which all of the end-client objects subscribe, but then subscribes to each Rule's list and simply forwards to its own list. This would maintain the "the Rule implements the RuleListener list" idea, but allowing for the optimization of delegation to avoid an overly repetitive subscription scheme. (It'd be basically the same as the House/Engine class exposing an API for Rules to call in order to dispatch an event as you suggest, but the API would itself just be the RuleListener interface, delegated through the House/Engine class).
In that way, the individual Rule implementations would all still provide for the possibility of having multiple listeners, and ultimately the RuleListener dispatching would originate with those classes, but the issue of redundancy that you are talking about would be addresed.
Pete
.
- Follow-Ups:
- Re: Design decision for a game
- From: Peter Duniho
- Re: Design decision for a game
- References:
- Design decision for a game
- From: pek
- Re: Design decision for a game
- From: Peter Duniho
- Re: Design decision for a game
- From: pek
- Re: Design decision for a game
- From: Peter Duniho
- Re: Design decision for a game
- From: Tom Anderson
- Design decision for a game
- Prev by Date: Re: Design decision for a game
- Next by Date: Re: Design decision for a game
- Previous by thread: Re: Design decision for a game
- Next by thread: Re: Design decision for a game
- Index(es):
Relevant Pages
|