Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvice with Class Hierarchy for Game Items
    primarykey
    data
    text
    <p>I'm writing a MUD engine and I've just started on the game object model, which needs to be extensible.</p> <p>I need help mainly because what I've done feels messy, but I can't think of a another solution that works better.</p> <p>I have a class called <code>MudObject</code>, and another class called <code>Container</code>, A container can contain multiple <code>MudObjects</code>, but is a <code>MudObject</code> itself, however <code>MudObject</code>s need to know what they are contained in.</p> <p>So they look something like this:</p> <pre><code>public abstract class MudObject { Container containedBy; } public abstract class Container : MudObject { List&lt;MudObject&gt; Contains; } </code></pre> <p><em>(please note these are just example and some qualifiers and access modifiers, properties and such are missed off)</em></p> <p>Now just this in itself seems messy, but lets add something else to the mix:</p> <p><code>Item</code> is a <code>MudObject</code> that all visual items (such as weapons) will be inherited from, however some of these need to be containers too (like chests). But theres no such as multiple inheritance in c#, So it comes down to interfaces, the best choice would be to make the container an interface (as far as I can see) However there was a reason I didn't want it to be, that being that adding an <code>MudObject</code> to a container will cause the container to update the <code>MudObject</code>s <code>.containedBy</code> value.</p> <p>Any ideas that would make this work, or am I falling into the trap of making things too complicated?<br> If so what else could you suggest?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload