コード例 #1
0
        public static FactoryBase GetFactory(string shapeName)
        {
            FactoryBase factory;

            switch (shapeName)
            {
            case "Square":
                factory = new SquareFactory();
                break;

            case "Triangle":
                factory = new TriangleFactory();
                break;

            default:
                factory = null;
                break;
            }
            return(factory);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            IPolygonFactory factory;

            var shape = Console.ReadLine();

            switch (shape)
            {
            case "Rectangle":
                factory = new RectangleFactory();
                break;

            case "Triangle":
                factory = new TriangleFactory();
                break;

            default:
                throw new NotImplementedException();
            }

            var button = factory.CreatePolygon();

            button.DrawPolygon();
        }