Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

factory method and constructors

13 views
Skip to first unread message

Firkraag

unread,
Jan 7, 2012, 5:16:11 AM1/7/12
to
Hi, consider the following code:

class Bicycle : Vehicle {}
class Truck : Vehicle {}

abstract class Vehicle
{
public abstract void Move(int x, int y);

public static Vehicle Make(int choice)
{
if (choice == 1)
{
return new Bicycle();
}
else if (choice == 2)
{
return new Truck(int howManyWheels); // ?
}
...

}
}

Maybe I am missing something obvious, but what would be the best way
to handle constructors with various number of arguments here?
0 new messages