Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that composition makes the most sense here, however I'd recommend dynamic composition over static composition in order to account for anatomical anomalies (missing limbs, etc)</p> <pre><code>public abstract class Body { public Dictionary&lt;string, BodyPart&gt; BodyParts { get; set; } //other properties, methods, etc. } </code></pre> <p>Your BodyPart class might be purely virtual...</p> <pre><code>public abstract class BodyPart { } </code></pre> <p>You can add specific types of body parts:</p> <pre><code>public abstract class Limb : BodyPart { public float Length { get; set; } public abstract void Move(); } </code></pre> <p>If you need to, create subclasses for arms, legs, etc</p> <pre><code>public class Arm : Limb { public override void Move() { Debug.WriteLine("Arm is moving"); } } </code></pre> <p>Finally, you can subclass your body to be human-specific:</p> <pre><code>public class HumanBody : Body { //properties and methods specific to the human body } </code></pre> <p>Putting it all together, you can create a robust HumanBody dynamically:</p> <pre><code>HumanBody body = new HumanBody(); Arm leftArm = new Arm(){ Length=24F }; Arm rightArm = new Arm(){ Length=24F }; //create other parts body.BodyParts.Add(new KeyValuePair&lt;string, BodyPart&gt;("LeftArm",leftArm)); body.BodyParts.Add(new KeyValuePair&lt;string, BodyPart&gt;("RightArm",rightArm)); //add other parts </code></pre> <p>While this is very flexible, the obvious disadvantage is that you'll have to do a fair amount of casting if you actually want to <em>use</em> any of the body parts:</p> <pre><code>Arm leftArm = body.BodyParts["LeftArm"] as Arm; leftArm.Move(); </code></pre> <p>Not bad for 2 lines of code, but should you need to coordinate movements the added overhead of casting could be too onerous.</p> <p>That's my 2c.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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