-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
49 lines (40 loc) · 910 Bytes
/
Program.cs
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
namespace DesignPatterns.Bridge;
interface ILaunch
{
void Run();
}
class Engine : ILaunch
{
public void Run() => Console.WriteLine("Engine running...");
}
interface IVehicle
{
void Drive();
}
class SchoolBus(ILaunch launch) : IVehicle
{
public void Drive()
{
ArgumentNullException.ThrowIfNull(launch,"There is no engine in the school bus.");
launch.Run();
Console.WriteLine("SchoolBus driving");
}
}
class Taxi(ILaunch launch) : IVehicle
{
public void Drive() {
ArgumentNullException.ThrowIfNull(launch,"There is no engine in the car.");
launch.Run();
Console.WriteLine("Taxi driving");
}
}
class App
{
public static void Main(string[] args)
{
IVehicle schoolBus = new SchoolBus(new Engine());
schoolBus.Drive();
IVehicle taxi = new Taxi(null);
taxi.Drive();
}
}