代码
using System;
using System.Collections.Generic;
public interface ILog
{
void Log(string str);
}
public class TxtLog:ILog
{
public void Log(string str)
{
Console.WriteLine("Text Record:"+str);
}
}
public class SQLServerLog:ILog
{
public void Log(string str)
{
Console.WriteLine("SQLServerLog Record:"+str);
}
}
public class OracleLog:ILog
{
public void Log(string str)
{
Console.WriteLine("OracleLog Record:"+str);
}
}
public abstract class Message
{
public ILog miketest;
public abstract void Log(string str);
}
public class NoEncrytMessage:Message
{
public NoEncrytMessage(ILog log)
{
miketest=log;
}
public override void Log(string str)
{
Console.WriteLine("不用加密!!");
miketest.Log(str);
}
}
public class EncrytMessage:Message
{
public EncrytMessage(ILog log)
{
miketest=log;
}
public override void Log(string str)
{
Console.WriteLine("加密加密字符");
miketest.Log(str);
}
}
public class MyClass
{
public static void Main()
{
Message message=new EncrytMessage(new OracleLog());
message.Log("MIke");
Console.WriteLine("**********************");
Message mymessage=new NoEncrytMessage(new SQLServerLog());
mymessage.Log("Janus");
Console.WriteLine("***********************");
mymessage=new EncrytMessage(new SQLServerLog());
mymessage.Log("Janus");
Console.ReadLine();
}
}
using System.Collections.Generic;
public interface ILog
{
void Log(string str);
}
public class TxtLog:ILog
{
public void Log(string str)
{
Console.WriteLine("Text Record:"+str);
}
}
public class SQLServerLog:ILog
{
public void Log(string str)
{
Console.WriteLine("SQLServerLog Record:"+str);
}
}
public class OracleLog:ILog
{
public void Log(string str)
{
Console.WriteLine("OracleLog Record:"+str);
}
}
public abstract class Message
{
public ILog miketest;
public abstract void Log(string str);
}
public class NoEncrytMessage:Message
{
public NoEncrytMessage(ILog log)
{
miketest=log;
}
public override void Log(string str)
{
Console.WriteLine("不用加密!!");
miketest.Log(str);
}
}
public class EncrytMessage:Message
{
public EncrytMessage(ILog log)
{
miketest=log;
}
public override void Log(string str)
{
Console.WriteLine("加密加密字符");
miketest.Log(str);
}
}
public class MyClass
{
public static void Main()
{
Message message=new EncrytMessage(new OracleLog());
message.Log("MIke");
Console.WriteLine("**********************");
Message mymessage=new NoEncrytMessage(new SQLServerLog());
mymessage.Log("Janus");
Console.WriteLine("***********************");
mymessage=new EncrytMessage(new SQLServerLog());
mymessage.Log("Janus");
Console.ReadLine();
}
}