Witam, napisałem własną implementację wzorca projektowego: prototyp. Chciałbym się dowiedzieć czy jest ona poprawna.
public enum Handle
{
Wooden,
Iron,
Steel,
Glass,
Gold
}
public enum Edge
{
Iron,
Steel,
Glass,
Gold
}
public enum WeaponType
{
Sword,
Mace,
Axe
}
public class WeaponCreator
{
private int cost;
private Handle handle;
private Edge edge;
private WeaponType weaponType;
public WeaponCreator(int cost, Handle handle, Edge edge, WeaponType weaponType)
{
this.cost = cost;
this.handle = handle;
this.edge = edge;
this.weaponType = weaponType;
}
public Weapon CreateWeapon() => new Weapon(cost, handle, edge, weaponType);
}
public interface ICloneable
{
object Clone();
}
public class Weapon : ICloneable
{
public int cost { get; }
public Handle handle { get; }
public Edge edge { get; }
public WeaponType weaponType { get; }
public Weapon(int cost, Handle handle, Edge edge, WeaponType weaponType)
{
this.cost = cost;
this.handle = handle;
this.edge = edge;
this.weaponType = weaponType;
}
public object Clone() => MemberwiseClone();
public override string ToString() => $"Cost: {cost}, Type: {weaponType}, Handle: {handle}, Edge: {edge}";
}
static class Prototyp
{
public static void Test()
{
WeaponCreator weaponCreator = new WeaponCreator(9000, Handle.Glass, Edge.Gold, WeaponType.Sword);
var clone = weaponCreator.CreateWeapon().Clone();
Console.WriteLine(clone.ToString());
}
}