[MUD-Dev] SMAUG Code (was Personality Types)

Miroslav Silovic silovic at zesoi.fer.hr
Thu Aug 23 15:43:36 CEST 2001


"Alistair Milne" <krug at krug.org.uk> writes:

> You're implying here that the best Object Oriented approach is to
> use the equivalent of Get() and Set() methods.  In my experience,
> the better designed class is the one that has methods for the
> roles that the object will play, rather than simply direct access
> functions to the data.  For example when a player types 'look' in
> a room, rather than having methods in the Room class for
> GetLongDescription(), GetExits(), GetContainedThings(), etcetera,
> I would give it a DescribeYourself(ch) method, which takes a
> player's object as an argument, interrogates it to see how the
> text should be formatted, then sends along the relevant room
> description.  This approach is also portable to other classes, so
> they can also have a DescribeYourself() method, and you have a
> nice simple consistent interface.  Do the class-specific work
> inside that class, not at the Player's end:
 
>     void Player::look( Thing& subject )
>     {
>         subject.DescribeYourself( *this );
>     }

Looks like LambdaMOO core and ColdCore approach to me.

In both cases, the assumption is that there is only a single player
class. Besides, it just calls all the GetFoo from the Player, rather
than the room (GetVisualCapability, GetHearingCapability,
GetSmellCapability....) And if there is more than one Player type,
you will have something like

  switch(Player.isa()) {
  case Humanoid: ...
  case Troll: ...
  case Reptiloid: ...
  }

The proper approach is multiple polymorphic dispatch (here
demonstrated using TinyCLOS syntax, employed by Guile's GOOPS):

  (define-generic look)

  (define-method look (subject <Player>) (object <Described>)
     ;; the default, since all other cases inherit from (Player, Described)
     ;; pair.
     )

  (define-method look (subject <Player>) (object <Room>)
     ... )

  (define-method look (subject <Troll>) (object <Room>)
     ... )

  (define-method look (subject <Player>) (object <Thing>)
     ... )
etc.

--
How to eff the ineffable?
_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the mud-dev-archive mailing list