abstract class Logger { public void Log(string message) { Connect(); Write(message); Close(); } public abstract void Connect(); public abstract void Write(string message); public abstract void Close(); } class TxtLogger : Logger { public override void Connect() { Console.WriteLine("Txt File is Connected"); } public override void Write(string message) {
Console.WriteLine
(DateTime.Now.ToString()+":"+message);
} public override void Close() { Console.WriteLine("Txt log file is Closed"); } } class XmlLogger : Logger { public override void Connect() { Console.WriteLine("Xml log file is Connected"); } public override void Write(string message) {
Console.WriteLine
(DateTime.Now.ToString()
+ ":"
+ message);
} public override void Close() { Console.WriteLine("Xml log file is Closed"); } } class MainApp { static void Main() { Logger logger = null; logger = new TxtLogger(); logger.Log("it is normal");
Console.WriteLine
("-------------------------------------------");
logger = new XmlLogger(); logger.Log("it is normal"); } } |