caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dirk Thierbach <dthierbach@gmx.de>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons
Date: Tue, 26 Feb 2008 16:07:11 +0100	[thread overview]
Message-ID: <20080226150711.GB6521@feanor> (raw)
In-Reply-To: <47C3F96E.4080901@exalead.com>

On Tue, Feb 26, 2008 at 12:35:10PM +0100, Berke Durak wrote:
> In this adventure, things can contain other things; a class physical has a 
> list of things it contains, and an optional pointer to its container.
> 
> Persons, places and objects are things so they inherit from physical.  
> Hence, a forest is a place that can contain
> a sword (an object), a dragon (a person) or another place (a small house).  
> Persons can be contained in places
> or things (coffins).
> 
> The problem is that the main game loop gets the current location by taking 
> the container of the hero... which is a physical.  However, it needs to 
> call the place-specific method "go".

I think I wouldn't use objects at all in this situation. You're trying
to model the location-tree of "physical" things. A tree must be uniform
in its contents, but you want to put different things into it. That
means you must use an algebraic type, or variants. I'd probably either
use a zipper, or connect the tree nodes with "refs" for the non-pure
version. 

Attaching operations like "go" to a specific object is also a leftover
from the "everything is an object" philosophy. If you must move a physical
thing, just move it. If you need to attach special behaviour for some
sort of movements, find out what it depends on (source, destination,
thing moved, or a combination) and handle those cases in the move-routine.

- Dirk




  parent reply	other threads:[~2008-02-26 15:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-26 11:35 Berke Durak
2008-02-26 12:14 ` [Caml-list] " Richard Jones
2008-02-26 14:28   ` Berke Durak
2008-02-26 14:48     ` Richard Jones
2008-02-26 14:59       ` Berke Durak
2008-02-27 13:26   ` Tiphaine.Turpin
2008-02-29 10:36     ` Berke Durak
2008-02-29 12:23       ` Tiphaine.Turpin
2008-02-26 12:48 ` ketti
2008-02-26 13:10 ` Berke Durak
2008-02-26 15:07 ` Dirk Thierbach [this message]
2008-02-26 16:25   ` Berke Durak
2008-02-27  7:37     ` Dirk Thierbach
2008-02-27 10:26       ` Berke Durak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080226150711.GB6521@feanor \
    --to=dthierbach@gmx.de \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).