So at first, I had the following constructor.
public WaitPanelThread(Point origin,
int delay,
//bool westEast,
String direction,
Panel panel,
Color colour,
Semaphore semaphore,
Semaphore semaphore2,
Semaphore parkSemaphore,
Semaphore nextSlot,
Buffer buffer,
Buffer buffer2,
Buffer parkBuffer,
String panelParkSpot,
String nextSpot)
{
this.origin = origin;
this.delay = delay;
this.nextSpot = nextSpot;
this.parkBuffer = parkBuffer;
this.nextSlot = nextSlot;
this.panelParkSpot = panelParkSpot;
//this.westEast = westEast;
this.direction = direction;
this.parkSemaphore = parkSemaphore;
this.panel = panel;
this.colour = colour;
this.plane = origin;
if (direction == "down")
{
this.yDelta = 2;
this.xDelta = 0;
}
if (direction == "left")
{
this.xDelta = -10;
this.yDelta = 0;
}
if (direction == "right")
{
this.xDelta = 10;
this.yDelta = 0;
}
this.panel.Paint += new PaintEventHandler(this.panel_Paint);
//this.xDelta = westEast ? +10 : -10;
//this.yDelta = 0;
this.semaphore = semaphore;
this.semaphore2 = semaphore2;
this.buffer = buffer;
this.buffer2 = buffer2;
}
And then I realized, for some objects I would need three more parameters. So I overloaded the constructor with three more parameters, copy-pasted the code and assigned the extra parameters as well.
public WaitPanelThread(Point origin,
int delay,
//bool westEast,
String direction,
Panel panel,
Color colour,
Semaphore semaphore,
Semaphore semaphore2,
Semaphore parkSemaphore,
Semaphore nextSlot,
Buffer buffer,
Buffer buffer2,
Buffer parkBuffer,
String panelParkSpot,
String nextSpot,
bool isTurn,
Semaphore altSem,
Buffer altBuf)
{
this.origin = origin;
this.delay = delay;
this.nextSpot = nextSpot;
this.parkBuffer = parkBuffer;
this.nextSlot = nextSlot;
this.panelParkSpot = panelParkSpot;
//this.westEast = westEast;
this.direction = direction;
this.parkSemaphore = parkSemaphore;
this.isTurn = isTurn;
this.panel = panel;
this.colour = colour;
this.plane = origin;
this.altSem = altSem;
this.altBuf = altBuf;
if (direction == "down")
{
this.yDelta = 2;
this.xDelta = 0;
}
if (direction == "left")
{
this.xDelta = -10;
this.yDelta = 0;
}
if (direction == "right")
{
this.xDelta = 10;
this.yDelta = 0;
}
this.panel.Paint += new PaintEventHandler(this.panel_Paint);
//this.xDelta = westEast ? +10 : -10;
//this.yDelta = 0;
this.semaphore = semaphore;
this.semaphore2 = semaphore2;
this.buffer = buffer;
this.buffer2 = buffer2;
}
So as you can see, The two constructors are mostly identical in its implementation except for the three extra parameters (One boolean, one semaphore and one buffer.) What I want to know is, instead of writing all the code in the overloaded constructor, is there a way to reference the first constructor and only have to write extra code for the extra parameters?
I'm talking about something like using the "Super()" method in an inherited class (I looked into it, can't be done here because they are within the same class).
Thank you.