Created
October 11, 2018 21:01
-
-
Save sevperez/b5626a2b32bc306b801ef873b055c914 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
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