Created
August 27, 2018 07:14
-
-
Save marhoily/25ee36ad1ba9251d618fc7bc3523768e to your computer and use it in GitHub Desktop.
This file contains 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
using System.Text; | |
using FluentAssertions; | |
using Xunit; | |
namespace DesignPatters | |
{ | |
public sealed class Pattern5 | |
{ | |
interface IDrawable | |
{ | |
void Draw(StringBuilder canvas); | |
} | |
class Ellipse : IDrawable | |
{ | |
public void Draw(StringBuilder canvas) | |
{ | |
canvas.Append("Ellipse;"); | |
} | |
} | |
class Square : IDrawable | |
{ | |
public void Draw(StringBuilder canvas) | |
{ | |
canvas.Append("Square;"); | |
} | |
} | |
class Compound : IDrawable | |
{ | |
private readonly IDrawable[] _list; | |
public Compound(params IDrawable[] list) { _list = list; } | |
public void Draw(StringBuilder canvas) | |
{ | |
foreach (var drawable in _list) | |
drawable.Draw(canvas); | |
} | |
} | |
[Fact] | |
public void Test() | |
{ | |
var canvas = new StringBuilder(); | |
new Compound(new Square(), new Ellipse()) | |
.Draw(canvas); | |
canvas.ToString().Should().Be("Square;Ellipse;"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment