What you might want to do is use the Vistor pattern,
which allows you to defer the type-specific dispatch.
(see e.g.
http://www.ti.et-inf.uni-siegen.de/Entwurfsmuster/ArtikelImport/osefa/patterns/visitor/intent.htm
or
http://www.ootips.org/visitor-pattern.html)
Thomas
On Monday 07 May 2001 13:58, Gerhard Austaller wrote:
> Hi
>
> I've a more general question on using messages for distributed
> computing. I've written a small distributed whiteboard that uses
> messages for spreading the whiteboard's content and user interactions
> like clearing the whiteboard. It works but know I'm wondering if the way
> I programmed the whiteboard is appropriate: Depending on the kind of a
> message and it's content I'm calling a (local) method as shown in this
> example ...
>
> public void onMessage(Message message) {
> try {
> if (message instanceof ObjectMessage) {
> ObjectMessage msg = (ObjectMessage) message;
> canvas.addLine((Line)msg.getObject());
> } else if (message instanceof MapMessage) {
> MapMessage msg = (MapMessage) message;
> if (msg.getString("command").equals("clear"))
> canvas.clear();
> }
> } catch (Exception e) {
> System.out.println("Exception in onMessage(): " +
> e.toString());
> }
> }
>
> But if I had to distinguish much more messages I would get many cascaded
> ifs - and I don't think that's what I want in an object-oriented
> language? Maybe there are well-known pattern (that I obviously don't
> know) how to solve this ...
>
> MfG
> Gerhard Austaller
>
> ------------------------------------------------------
> SwiftMQ developers mailing list * http://www.swiftmq.com
> To unsubscribe from this list, send an eMail to
> [EMAIL PROTECTED] and write in the body of your message:
> UNSUBSCRIBE developers <your-email-address>
> Archive: http://www.mail-archive.com/developers@mail.iit.de/
------------------------------------------------------
SwiftMQ developers mailing list * http://www.swiftmq.com
To unsubscribe from this list, send an eMail to
[EMAIL PROTECTED] and write in the body of your message:
UNSUBSCRIBE developers <your-email-address>
Archive: http://www.mail-archive.com/developers@mail.iit.de/