已经有的存在的类,可能是别人写的,反正就是我们现在想拿来用的类SpecialOutput
public class SpecialOutput
{
public void PrintSquare()
{
for(Int32 i=0; i<4; i++)
Console.WriteLine("* * * *");
}
public void PrintUnderline()
{
Console.WriteLine("_______");
}
}
我们自己的类Output想使用它的功能{
public void PrintSquare()
{
for(Int32 i=0; i<4; i++)
Console.WriteLine("* * * *");
}
public void PrintUnderline()
{
Console.WriteLine("_______");
}
}
public class Output
{
private static SpecialOutput so= new SpecialOutput();
public void PrintSquare()
{
so.PrintSquare();
}
public void PrintUnders()
{
so.PrintUnderline();
}
}
测试程序{
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
{
public static void Main()
{
Output o = new Output();
o.PrintSquare();
o.PrintUnders();
Console.ReadLine();
}
}