设计模式---适配器模式(从百度转回来的)

53a941eefca8a5ecb3fb9578.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
abstract class Birds
{
public abstract void Fly();

public abstract void Shout();
}

class Duck : Birds
{
public override void Fly()
{
Console.WriteLine("鸭子飞");
}

public override void Shout()
{
Console.WriteLine("鸭子叫唤");
}
}

class Chick : Birds
{
public override void Fly()
{
Console.WriteLine("小鸡飞");
}

public override void Shout()
{
Console.WriteLine("小鸡飞");
}
}

class Adapter : Birds
{
private Eagle eagle = new Eagle();

public override void Fly()
{
eagle.Fly();
}

public override void Shout()
{
eagle.Shout();
}
}

class Eagle
{
public void Fly()
{
Console.WriteLine("老鹰飞");
}

public void Shout()
{
Console.WriteLine("老鹰叫唤");
}
}

class Client
{
public static void Main()
{
Birds b = new Duck();
b.Fly();
b.Shout();
b = new Chick();
b.Fly();
b.Shout();
b = new Adapter();
b.Fly();
b.Shout();
Console.Read();
}
}
}