using System;
// Interface cho các sản phẩm
public interface ISeat
{
string GetDescription();
}
public interface IWheel
{
string GetDescription();
}
public interface IEngine
{
string GetDescription();
}
// Các sản phẩm cụ thể
public class CarSeat : ISeat
{
public string GetDescription() => "Car seat with 4 seats.";
}
public class TruckSeat : ISeat
{
public string GetDescription() => "Truck seat with 2 seats.";
}
public class BikeSeat : ISeat
{
public string GetDescription() => "Bike seat with 2 seats.";
}
public class CarWheel : IWheel
{
public string GetDescription() => "Car wheel with large size.";
}
public class TruckWheel : IWheel
{
public string GetDescription() => "Truck wheel with large size.";
}
public class BikeWheel : IWheel
{
public string GetDescription() => "Bike wheel with small size.";
}
public class CarEngine : IEngine
{
public string GetDescription() => "Car engine using gasoline.";
}
public class TruckEngine : IEngine
{
public string GetDescription() => "Truck engine using diesel.";
}
public class BikeEngine : IEngine
{
public string GetDescription() => "Bike engine using gasoline.";
}
// Interface cho VehicleFactory
public interface IVehicleFactory
{
ISeat CreateSeat();
IWheel CreateWheel();
IEngine CreateEngine();
}
// Các factory cụ thể
public class CarFactory : IVehicleFactory
{
public ISeat CreateSeat() => new CarSeat();
public IWheel CreateWheel() => new CarWheel();
public IEngine CreateEngine() => new CarEngine();
}
public class TruckFactory : IVehicleFactory
{
public ISeat CreateSeat() => new TruckSeat();
public IWheel CreateWheel() => new TruckWheel();
public IEngine CreateEngine() => new TruckEngine();
}
public class BikeFactory : IVehicleFactory
{
public ISeat CreateSeat() => new BikeSeat();
public IWheel CreateWheel() => new BikeWheel();
public IEngine CreateEngine() => new BikeEngine();
}
class Program
{
static void Main(string[] args)
{
IVehicleFactory carFactory = new CarFactory();
IVehicleFactory truckFactory = new TruckFactory();
IVehicleFactory bikeFactory = new BikeFactory();
// Tạo các sản phẩm cho xe hơi
Console.WriteLine("Car Factory:");
Console.WriteLine(carFactory.CreateSeat().GetDescription());
Console.WriteLine(carFactory.CreateWheel().GetDescription());
Console.WriteLine(carFactory.CreateEngine().GetDescription());
Console.WriteLine();
// Tạo các sản phẩm cho xe tải
Console.WriteLine("Truck Factory:");
Console.WriteLine(truckFactory.CreateSeat().GetDescription());
Console.WriteLine(truckFactory.CreateWheel().GetDescription());
Console.WriteLine(truckFactory.CreateEngine().GetDescription());
Console.WriteLine();
// Tạo các sản phẩm cho xe máy
Console.WriteLine("Bike Factory:");
Console.WriteLine(bikeFactory.CreateSeat().GetDescription());
Console.WriteLine(bikeFactory.CreateWheel().GetDescription());
Console.WriteLine(bikeFactory.CreateEngine().GetDescription());
}
}