TXT

bridge pattern example

By Sheila Smith,2014-05-19 17:48
10 views 0
bridge pattern example

//.NETÆ?Ì?ϵÄDatabase Log

     Log dblog = new DatabaseLog();

     dblog.Implementor = new NImpLog();

     dblog.Write("DotNet plantform");

     //JavaÆ?Ì?ϵÄText File Log

     Log txtlog = new TextFileLog();

     txtlog.Implementor = new JImpLog();

     txtlog.Write("Java plantform");

// bridge

    public abstract class ImpLog

    {

     public abstract void Execute(string msg); }

public class NImpLog : ImpLog

    {

     public override void Execute(string msg)

     {

     //......NET

     Console.WriteLine(msg);

     }

    }

public class JImpLog : ImpLog

    {

     public override void Execute(string msg)

     {

     //...... JavaÆ?Ì?

     Console.WriteLine(msg);

     }

    }

// log

    public abstract class Log

    {

     protected ImpLog implementor;

     public ImpLog Implementor

     {

     set { implementor = value; }

     }

     public virtual void Write(string log)

     {

     implementor.Execute(log);

     }

    }

    public class DatabaseLog : Log {

     public override void Write(string log)

     {

     implementor.Execute(log);

     }

    }

    public class TextFileLog : Log {

     public override void Write(string log)

     {

     implementor.Execute(log);

     }

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com