]> wagnertech.de Git - mDoc.git/blobdiff - csharp/mutil/MessageTool.cs
Squashed commit of the following:
[mDoc.git] / csharp / mutil / MessageTool.cs
diff --git a/csharp/mutil/MessageTool.cs b/csharp/mutil/MessageTool.cs
new file mode 100644 (file)
index 0000000..d4fa406
--- /dev/null
@@ -0,0 +1,32 @@
+using System;
+
+namespace mutil {
+
+public interface MessageToolImpl{
+    void send(string message);
+}
+public class MessageTool : MessageToolImpl {
+    // strategy pattern
+    //private messageToolImpl MessageToolImpl = null;
+    public MessageToolImpl MessageToolImpl {private get; set;}
+
+    public void send(string message) {
+        if (MessageToolImpl == null) throw new System.Exception("set MessageToolImpl before sending a message.");
+        MessageToolImpl.send(message);
+    }
+    // singleton
+    static private MessageTool theInstance = null;
+
+    static public MessageTool getInstance() {
+        if (theInstance == null) theInstance = new MessageTool();
+        return theInstance;
+    }
+}
+
+public class ConsoleMessageTool : MessageToolImpl {
+    public void send(string message) {
+        Console.WriteLine(message);
+    }
+}
+
+} // namespace
\ No newline at end of file