   [C#] Am I using the base keyword in a suitable manner?
  I currently have an abstract base class set out as follows:    public abstract class EntityBB : IOctree_Object, IGUI_Object    {   private Animation2D animation;   private RigidBody3D body;   private Vector3 forward = Vector3.Forward; // Direction the quad is facing   private bool isAlive = false;    // Entity is not alive (in use) until spawned   private Quadrangle quad;  private CD_BoundingSphere octreeSphere;   private Vector3 scale; // Size/scale of entity   private float speed;   public static bool IsValid(Entity3D entity)   {  return entity.IsAlive;   }   public EntityBB()   {  quad = Game1.Instance.pool_Quadrangle.GetNewValidObject();  quad.IsAlive = true;   }   public virtual void Draw()   {  if (animation != null)  { // Set source rectangle to draw from for current animation frame quad.UV_LL = animation.source_UL; quad.UV_UR = animation.source_UR; quad.UV_LL = animation.source_LL; quad.UV_LR = animation.source_LR;  }  quad.Draw();   }   public virtual void Kill()   {  isAlive = false;  // Remove this entity from the physics simulation  Game1.Instance.Physics3D.RemoveBody(this);   }   public virtual void Spawn(Vector3 scale, Quaternion rotation, Vector3 translation)   {  quad.Position = translation;  quad.Width = scale.X;  quad.Height = scale.Y;  octreeSphere = new CD_BoundingSphere( translation, Math.Max(quad.Height, quad.Width) * 0.5f );  body = new RigidBody3D(translation);  // Add this entity to the physics simulation  Game1.Instance.Physics3D.AddBody(this);  isAlive = true;   }I wish set common parameters for all classes that inherit from it in one method, for example the spawn method.Is it correct to call base.Spawn() first, from the class that inherits from this base class, so that all common parameters can be set.  Then class specific parameters can be changed in the class itself.In other words:    class EntityBB_Enemy : EntityBB    {   public static EntityBB_Enemy Instance()   {  return new EntityBB_Enemy();   }   public EntityBB_Enemy() { }   public override void Kill()   {  base.Kill();  // Now play specific death sound related to this class   }   public override void Spawn(Vector3 scale, Quaternion rotation, Vector3 translation)   {  base.Spawn(scale, rotation, translation);  Animation = new Animation2D(Effect_Manager.Instance.textureList[Texture], 1.0f, 32, 32);  Animation.Play(0, 0, true);  // [Body]  Body.Mass = 1.0f;  Body.Shapes.Add(new CD_AABB(translation, scale.X, scale.Y, scale.Z));  Body.Type = RigidBody3D_Type.Static;  Speed = 50.0f;   }
  I dont see anything wrong with this, other then forgetting to call base.Kill() you could consider this instead:Base class:   virtual void OnKill(){}   public virtual void Kill()   {  isAlive = false;  // Remove this entity from the physics simulation  Game1.Instance.Physics3D.RemoveBody(this);  OnKill();   }Then you simply override OnKill().   ;  That's a good idea; it would be great to have the method called automatically.  I can't think of a convenient way of doing it though.Your suggestion, albeit good, would only serve to confuse me because I would often end up overriding Kill() by mistake.   ;  doh, the Kill method shouldnt be virtual, I was jsut blind copy & pasting   ;  This looks like a bad design. If you need to augment behaviour, favour containment over inheritance if possible with a decorator.interface IOctree_Object{    event Action<Vector3D,etc> Spawned; //base event}class EntityBB : IOctree_Object{    event Action<Vector3D,etc> Spawned;    ///methods}class EntityBB_Enemy : IOctree_Object //decorate the wrapped object{    IOctree_Object m_wrappedEntity; //wrap it    EntityBB_Enemy ( IOctree_Object _wrappedObject)    {   m_wrappedEntity = _wrappedObject; //receive it in a configured state   m_wrappedEntity.Spawned += SpawnedHandler;    }};Beware.;Quote:Original post by ZahlmanBeware.I had a read through the wiki but the final solution doesn't make sense to me:    public class Report    {    }    abstract class ReportGenerator    {   public Report CreateReport()   {  Tabulate();  // Generate the general report object  // ...  return new Report();   }   protected abstract void Tabulate();    }    class ConcreteReportGenerator : ReportGenerator    {   protected override void Tabulate()   {  // Tabulate data in the store-specific way  // ...   }    }Is it suggesting that I duplicate all the code for each overridden method?  Stating that the base class method (Tabulate) should be abstract means that the derived classes must have an override method for that base method.Or have I got that completely wrong?;  You're not wrong, it's just that it expects implementers to provide tabulating functionality. If it shouldn't, make it virtual with a do nothing implementation, or default tabulation or whatever I guess.I'd still favour decoration if possible.   ;  If I were to go with what I think gameXcore was saying, would that be acceptable?  It is the design choice that is most apparent to me.So the base class would have:   public void Spawn(Vector3 scale, Quaternion rotation, Vector3 translation)   {  quad.Position = translation;  quad.Width = scale.X;  quad.Height = scale.Y;  octreeSphere = new CD_BoundingSphere( translation, Math.Max(quad.Height, quad.Width) * 0.5f );  body = new RigidBody3D(translation);  // Add this entity to the physics simulation  Game1.Instance.Physics3D.AddBody(this);  isAlive = true;  Spawn();   }   protected abstract void Spawn();and the derived class would have:   protected override void Spawn()   {  Animation = new Animation2D(Texture, 1.0f, 32, 32);  Animation.Play(0, 0, true);  // [Body]  Body.Mass = 1.0f;  Body.Shapes.Add(new CD_AABB(Position, Scale.X, Scale.Y, Scale.Z));  Body.Type = RigidBody3D_Type.Static;  Speed = 50.0f;   }Please points out any failings, if you spot them.   