Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created October 11, 2018 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevperez/b5626a2b32bc306b801ef873b055c914 to your computer and use it in GitHub Desktop.
Save sevperez/b5626a2b32bc306b801ef873b055c914 to your computer and use it in GitHub Desktop.
using System;
namespace decorator_0
{
class Program
{
static void Main(string[] args)
{
var msg = "I love C-sharp";
var simpleMsg = new SimpleMessage(msg);
var excitedMsg = new ExcitedMessage(msg);
var quizzicalMsg = new QuizzicalMessage(msg);
var excitedAndQuizzicalMsg = new ExcitedAndQuizzicalMessage(msg);
SimpleMessage[] messages = { simpleMsg, excitedMsg, quizzicalMsg, excitedAndQuizzicalMsg };
foreach (SimpleMessage m in messages)
{
m.PrintMessage();
}
// I love C-sharp
// I love C-sharp!!!
// I love C-sharp???
// I love C-sharp!!!???
}
}
public class SimpleMessage
{
private string Content;
public SimpleMessage(string content)
{
this.Content = content;
}
public string GetMessage()
{
return this.Content;
}
public void PrintMessage()
{
Console.WriteLine(this.GetMessage());
}
}
public class ExcitedMessage : SimpleMessage
{
public ExcitedMessage(string content)
: base(content + "!!!") {}
}
public class QuizzicalMessage : SimpleMessage
{
public QuizzicalMessage(string content)
: base(content + "???") { }
}
public class ExcitedAndQuizzicalMessage : SimpleMessage
{
public ExcitedAndQuizzicalMessage(string content)
: base(content + "!!!???") { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment