All pastes #943237 Raw Edit

RickyWh

public text v1 · immutable
·published 2008-03-15 02:13 UTC
rendered paste body
using System;
using System.Collections;
using System.Collections.Generic;

namespace RickyTest
{
    public class Starter
    {
        public static void Main(string [] shapeArray)
        {
		List<GeoShape> shapes = new List<GeoShape>();
		
		GeoShape obj = null;
		
		foreach(string shape in shapeArray)
		{
			if(shape.ToUpper() == "R")
			{
				obj = new Rectangle();
			}
			else if(shape.ToUpper() == "E")
			{
				obj = new Ellipse();
			}
			else if(shape.ToUpper() == "T")
			{
				obj = new Triangle();
			}
			else 
			{
				continue;
			}
			shapes.Add(obj);
		}
		
		foreach(GeoShape shape in shapes)
		{
			shape.Draw(); // Polymorphic behavior?
		}
        }
    }
    public abstract class GeoShape
    {
        public GeoShape()
        {
            ++count;
            ID = count;
        }
        private static int count = 0;
        protected int ID = 0;

        public abstract void Draw();
    }
    public class Rectangle : GeoShape
    {
        public override void Draw()
        {
            Console.WriteLine("Drawing Shape {0} : rectangle", ID.ToString());
        }
    }
    public class Triangle : GeoShape
    {
        public override void Draw()
        {
            Console.WriteLine("Drawing Shape {0} : triangle", ID.ToString());
        }
    }
    public class Ellipse : GeoShape
    {
        public override void Draw()
        {
            Console.WriteLine("Drawing Shape {0} : ellipse", ID.ToString());
        }
    }
}