I’m learning how to properly apply OO principles in C#. I came across a little problem and I can’t figure out how to solve it. I run into the following problem:
The current situation:
public abstract class Foo
{
protected Foo()
{
//does nothing
}
}
public class Bar : Foo
{
public BarX ( int a, int b, int c) : base()
{
this.a = a;
this.b = b;
this.c = c;
}
public doStuff()
{
//does stuff
}
}
public class BarY : Foo
{
public Bar( int a, int b, int c) : base()
{
this.a = a;
this.b = b;
this.c = c;
}
public doStuff()
{
//does stuff
}
}
The point is that I hafe different types of Foo. In this case it would be circles and rectangles. I want them to have the same constructors as each type has the same attributes. They only have a different doStuff() method. I have tried many combinations but every time I try to move the arguments to the base class’s constructor it tells me that ‘some class does not contain a constructor that takes 0 arguments’ (or 3 arguments) depending how I move around my code.
My question is how I can move the assignment of a, b and c’s values to the abstract class’s constructor?
The following will work: