[MUD-Dev] Object Models (OO 101)
Gavin Doughtie
gavin at idealab.com
Fri Nov 17 14:54:02 CET 2000
<<EdNOte: Minorly edited for readability>>
Ben wrote:
> For example I have an object that is both a key and a monster.
> Instead of having an object type key_monster, I would like to have
> an object of type object that has inherited the properties of a
> key and of a monster. > Hyow do you handle these things?
Well, my kneejerk reaction is that you are describing "classic"
multiple inheritance, which in most of the "OO Purist" circles I run
in is considered a Bad Thing. In your example, you would construct a
new object type -- key_monster, in this case -- which would
_contain_ an instance of a key, an instance of a monster, plus any
special behavior that relates the two (i.e., the monster attacks you
if you attempt to open the wrong door with the key). In order for
the object to be used as either a key OR a monster, however, the
solution is usually to define an interface (Java supports interfaces
explictly, C++ allows you to define "pure virtual" classes that are
functionally similar). So, any object that promises to be
"monster-like" has its own implementations of Snarl, Attack,
RavageHelplessVirgin, etc., even if that object actually derives its
implementation from "key".
(Apologies if this is an old trope for you seasoned MUD-dev'ers, I'm
new on the list).
--
/*-----------------------------------
* Gavin Doughtie, Developer
* idealab!
* gavin at idealab.com
-----------------------------------*/
_______________________________________________
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