-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (47 loc) · 1.19 KB
/
Copy pathProgram.cs
File metadata and controls
58 lines (47 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
namespace Bridge;
public interface IRenderer
{
void RenderCircle(float x, float y, float radius);
}
public class VectorRenderer : IRenderer
{
public void RenderCircle(float x, float y, float radius)
{
Console.WriteLine($"Drawing vector circle at ({x},{y}) radius {radius}");
}
}
public class RasterRenderer : IRenderer
{
public void RenderCircle(float x, float y, float radius)
{
Console.WriteLine($"Rasterizing circle to pixels at ({x},{y}) radius {radius}");
}
}
public abstract class Shape(IRenderer renderer)
{
protected IRenderer Renderer { get; } = renderer;
public abstract void Draw();
}
public class Circle(float x, float y, float radius, IRenderer renderer) : Shape(renderer)
{
public override void Draw()
{
Renderer.RenderCircle(x, y, radius);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== Bridge Pattern Demo ===");
Console.WriteLine();
Shape circle = new Circle(10, 10, 5, new VectorRenderer());
circle.Draw();
circle = new Circle(25, 5, 12, new RasterRenderer());
circle.Draw();
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}