forked from sheng-jie/Design-Pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (33 loc) · 1.49 KB
/
Copy pathProgram.cs
File metadata and controls
41 lines (33 loc) · 1.49 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdapterPattern
{
class Program
{
static void Main(string[] args)
{
//在未定义充电标准之前,各个厂家充电线的实现各不相同,但都可以为自家品牌设备充电
USBLine usbLine = new USBLine();
usbLine.Charge();
Console.WriteLine("-------------------");
//随着电器设备越来越多,各家的充电设备不能通用,造成很多不便,为了共用,厂家联合推出标准充电接口。
//USB-Micro实现标准接口。
IChargingLine microLine = new USBMicroLine();
microLine.Charging();
Console.WriteLine("-------------------");
//现在手里有一个未实现充电标准的充电线,通过适配器,为小米5设备充电
Console.WriteLine("对象适配器模式:");
IChargingLine typeCLineAdapter = new USBTypecLineAdapter(usbLine);
typeCLineAdapter.Charging();
Console.WriteLine("-------------------");
//现在手里有一个未实现充电标准的充电线,通过适配器,为苹果设备充电
Console.WriteLine("类适配器模式:");
IChargingLine lightingLineAdapter = new USBlightingLineAdapter();
lightingLineAdapter.Charging();
Console.ReadLine();
}
}
}