26 lines
672 B
C#
26 lines
672 B
C#
|
Console.WriteLine("Willkommen zu Aufgabe5");
|
|||
|
|
|||
|
ObjectFactory<Fahrzeug> fahrzeugFactory = new ObjectFactory<Fahrzeug>();
|
|||
|
ObjectFactory<PKW> pkwFactory = new ObjectFactory<PKW>();
|
|||
|
ObjectFactory<LKW> lkwFactory = new ObjectFactory<LKW>();
|
|||
|
|
|||
|
Fahrzeug fahrzeug = fahrzeugFactory.CreateInstance();
|
|||
|
PKW pkw = pkwFactory.CreateInstance();
|
|||
|
LKW lkw = lkwFactory.CreateInstance();
|
|||
|
|
|||
|
fahrzeug.kennzeichen = "1";
|
|||
|
pkw.kennzeichen = "2";
|
|||
|
lkw.kennzeichen = "3";
|
|||
|
|
|||
|
Console.WriteLine(fahrzeug.Drive());
|
|||
|
Console.WriteLine(pkw.Drive());
|
|||
|
Console.WriteLine(lkw.Drive());
|
|||
|
|
|||
|
|
|||
|
public class ObjectFactory<T> where T : class, new()
|
|||
|
{
|
|||
|
public T CreateInstance()
|
|||
|
{
|
|||
|
return new T();
|
|||
|
}
|
|||
|
}
|