42
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
CarService carService = new CarService(new VacuumService());
8
carService.DoService();
9
10
Console.WriteLine("------------------");
11
12
carService = new CarService(new WashService());
13
carService.DoService();
14
}
15
16
public class CarService{
17
IService Service;
18
public CarService(IService service){
19
Service = service;
20
}
21
22
public void DoService(){
23
Service.Service();
24
}
25
}
26
27
public interface IService{
28
void Service();
29
}
30
31
public class VacuumService:IService{
32
public void Service(){
33
Console.WriteLine("Vacuum Service");
34
}
35
}
36
37
public class WashService:IService{
38
public void Service(){
39
Console.WriteLine("Wash Service");
40
}
41
}
42
}
Cached Result