设计模式 配置器

DesignPattern - Adapter

已经有的存在的类,可能是别人写的,反正就是我们现在想拿来用的类SpecialOutput
public class SpecialOutput
{
    
public void PrintSquare()
    
{
        
for(Int32 i=0; i<4; i++)
            Console.WriteLine(
"* * * *");
    }


    
public void PrintUnderline()
    
{
        Console.WriteLine(
"_______");
    }

}
我们自己的类Output想使用它的功能
public class Output
{
    
private static SpecialOutput so= new SpecialOutput();
    
    
public void PrintSquare()
    
{
        so.PrintSquare();
    }


    
public void PrintUnders()
    
{
        so.PrintUnderline();
    }

}
测试程序
public class App
{
    
public static void Main()
    
{
        Output o 
= new Output();
        o.PrintSquare();
        o.PrintUnders();
        Console.ReadLine();
    }

}
Adapter Demo
原文地址:https://www.cnblogs.com/Dabay/p/365142.html