Repository navigation
Expand file tree
/
Copy pathAbstractFactory.cs
More file actions
116 lines (97 loc) · 1.97 KB
/
Copy pathAbstractFactory.cs
File metadata and controls
116 lines (97 loc) · 1.97 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
namespace DesignPatterns
{
interface ICompany
{
IPhone Phone { get; }
ILaptop Laptop { get; }
}
interface IPhone
{
string getDetails();
}
interface ILaptop
{
string getDetails();
}
class Apple : ICompany
{
private IPhone phone;
private ILaptop laptop;
public Apple()
{
phone = new ApplePhone();
laptop = new AppleLaptop();
}
public IPhone Phone
{
get { return phone; }
}
public ILaptop Laptop
{
get { return laptop; }
}
}
class Samsung : ICompany
{
private IPhone phone;
private ILaptop laptop;
public Samsung()
{
phone = new SamsungPhone();
laptop = new SamsungLaptop();
}
public IPhone Phone
{
get { return phone; }
}
public ILaptop Laptop
{
get { return laptop; }
}
}
class ApplePhone: IPhone
{
public string getDetails()
{
return "IPhone 12 PRO, 128GB";
}
}
class SamsungPhone : IPhone
{
public string getDetails()
{
return "Galaxy S20, 128GB";
}
}
class AppleLaptop : ILaptop
{
public string getDetails()
{
return "MacBook PRO, 1TB";
}
}
class SamsungLaptop : ILaptop
{
public string getDetails()
{
return "Samsung laptop, 500GB";
}
}
class Shop
{
ICompany company;
public Shop(ICompany company)
{
this.company = company;
}
public void PrintPhoneDetails()
{
Console.WriteLine(company.Phone.getDetails());
}
public void PrintLaptopDetails()
{
Console.WriteLine(company.Laptop.getDetails());
}
}
}