Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace DefaultNamespace
- {
- public abstract class Factory<T>
- {
- public abstract T Create();
- }
- public abstract class TransportFabric<T> : Factory<T> where T : ITransport { }
- public class TruckFabric : TransportFabric<Truck>
- {
- public override Truck Create()
- {
- return new Truck();
- }
- }
- public class CarFabrick : TransportFabric<Car>
- {
- public override Car Create()
- {
- return new Car();
- }
- }
- public interface ITransport { }
- public class Truck : ITransport { }
- public class Car : ITransport { }
- public class Foo
- {
- private ITransport _truck;
- private ITransport _car;
- public Foo(TransportFabric<Truck> truckFactory, TransportFabric<Car> carFactory)
- {
- _truck = truckFactory.Create();
- _car = carFactory.Create();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment