Skip to content

Instantly share code, notes, and snippets.

@SlyNet
Created December 5, 2012 14:16
Show Gist options
  • Save SlyNet/4215808 to your computer and use it in GitHub Desktop.
Save SlyNet/4215808 to your computer and use it in GitHub Desktop.
class Surface
{
public virtual void Draw(Shape shape)
{
shape.Draw(this);
}
}
class EtchASketch : Surface
{
public override void Draw(Shape shape)
{
shape.Draw(this);
}
}
class Shape
{
public virtual void Draw(Surface surface)
{
Console.WriteLine("A shape is drawn on the surface with ink.");
}
public virtual void Draw(EtchASketch etchASketch)
{
Console.WriteLine("The knobs are moved in attempt to draw the shape.");
}
}
class Polygon : Shape
{
public override void Draw(Surface surface)
{
Console.WriteLine("A polygon is drawn on the surface with ink.");
}
public override void Draw(EtchASketch etchASketch)
{
Console.WriteLine("The knobs are moved in attempt to draw the polygon.");
}
}
class Quadrilateral : Polygon
{
public override void Draw(Surface surface)
{
Console.WriteLine("A quadrilateral is drawn on the surface with ink.");
}
public override void Draw(EtchASketch etchASketch)
{
Console.WriteLine("The knobs are moved in attempt to draw the quadrilateral.");
}
}
class Parallelogram : Quadrilateral
{
public override void Draw(Surface surface)
{
Console.WriteLine("A parallelogram is drawn on the surface with ink.");
}
public override void Draw(EtchASketch etchASketch)
{
Console.WriteLine("The knobs are moved in attempt to draw the parallelogram.");
}
}
class Rectangle : Parallelogram
{
public override void Draw(Surface surface)
{
Console.WriteLine("A rectangle is drawn on the surface with ink.");
}
public override void Draw(EtchASketch etchASketch)
{
Console.WriteLine("The knobs are moved in attempt to draw the rectangle.");
}
}
class Program
{
static void Main(string[] args)
{
Surface surface = new Surface();
Surface etchASketch = new EtchASketch();
var shapes = new List<Shape>
{
new Shape(),
new Polygon(),
new Quadrilateral(),
new Parallelogram(),
new Rectangle()
};
foreach (Shape shape in shapes)
{
surface.Draw(shape);
etchASketch.Draw(shape);
}
Console.ReadLine();
}
}
@Restuta
Copy link

Restuta commented Dec 6, 2012

Learning OOP again? )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment