When writing OO code I quite often use the constructor to pass sub class instances which means my sub classes always have a constructor like the C# example below. Is this ok or is their a better way?
class baseClassA
{
protected baseClassB m_ClassB;
public baseClassA(baseClassB classB)
{
m_ClassB = classB;
}
public void DoSomeProcessing()
{
m_ClassB.DoSomeProcessing();
ProcessResult();
}
public abstract void ProcessResult();
}
class subClassA : baseClassA
{
public subClassA() : base(subClassB);
public override void ProcessResult()
{
// some business logic
}
}
class baseClassA
{
protected baseClassB m_ClassB;
public baseClassA(baseClassB classB)
{
m_ClassB = classB;
}
public void DoSomeProcessing()
{
m_ClassB.DoSomeProcessing();
ProcessResult();
}
public abstract void ProcessResult();
}
class subClassA : baseClassA
{
public subClassA() : base(subClassB);
public override void ProcessResult()
{
// some business logic
}
}