-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFactory.cs
More file actions
55 lines (48 loc) · 2.04 KB
/
Copy pathAbstractFactory.cs
File metadata and controls
55 lines (48 loc) · 2.04 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
namespace Lab2.Patterns.AbstractFactory;
public interface IDevice
{
string Brand { get; }
string Model { get; }
string Category { get; }
string GetFullDescription();
}
public interface IDeviceFactory
{
string BrandName { get; }
Laptop CreateLaptop();
Netbook CreateNetbook();
EBook CreateEBook();
Smartphone CreateSmartphone();
}
public abstract record Device(string Brand, string Model, string Category) : IDevice
{
public string GetFullDescription() => $"{Brand} {Model} ({Category})";
}
public sealed record Laptop(string Brand, string Model) : Device(Brand, Model, nameof(Laptop));
public sealed record Netbook(string Brand, string Model) : Device(Brand, Model, nameof(Netbook));
public sealed record EBook(string Brand, string Model) : Device(Brand, Model, nameof(EBook));
public sealed record Smartphone(string Brand, string Model) : Device(Brand, Model, nameof(Smartphone));
public sealed class IProneFactory : IDeviceFactory
{
public string BrandName => "IProne";
public Laptop CreateLaptop() => new(BrandName, "IProne ProBook X");
public Netbook CreateNetbook() => new(BrandName, "IProne Air Mini");
public EBook CreateEBook() => new(BrandName, "IProne Read Lite");
public Smartphone CreateSmartphone() => new(BrandName, "IProne 16 Ultra");
}
public sealed class KiaomiFactory : IDeviceFactory
{
public string BrandName => "Kiaomi";
public Laptop CreateLaptop() => new(BrandName, "Kiaomi MiNote Pro");
public Netbook CreateNetbook() => new(BrandName, "Kiaomi Pocket 11");
public EBook CreateEBook() => new(BrandName, "Kiaomi Reader Ink");
public Smartphone CreateSmartphone() => new(BrandName, "Kiaomi RedFlag 15");
}
public sealed class BalaxyFactory : IDeviceFactory
{
public string BrandName => "Balaxy";
public Laptop CreateLaptop() => new(BrandName, "Balaxy Book Flex");
public Netbook CreateNetbook() => new(BrandName, "Balaxy Note Go");
public EBook CreateEBook() => new(BrandName, "Balaxy Pages");
public Smartphone CreateSmartphone() => new(BrandName, "Balaxy S42");
}