17 lines
418 B
C#
17 lines
418 B
C#
namespace DesignPatterns.Factory;
|
|
|
|
public abstract class Product
|
|
{
|
|
public double Price { get; set; } = 5;
|
|
public override string ToString() => "Product";
|
|
public static Product FactoryMethod(string productName)
|
|
{
|
|
return productName switch
|
|
{
|
|
"Smartphone" => new Smartphone(),
|
|
"Book" => new Book(),
|
|
_ => throw new ArgumentException()
|
|
};
|
|
}
|
|
}
|