Created
December 5, 2012 14:16
-
-
Save SlyNet/4215808 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Learning OOP again? )