-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
107 lines (88 loc) · 2.81 KB
/
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
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
using System;
namespace DefaultInterfaceMethods
{
/// <summary>
/// Default Interface Methods
/// https://www.infoq.com/articles/default-interface-methods-cs8/
/// https://github.com/dotnet/csharplang/blob/master/meetings/2018/LDM-2018-10-17.md
/// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods
/// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/constructors
/// </summary>
class Program
{
static void Main(string[] args)
{
BookBasket basket = new BookBasket(2);
//Console.WriteLine(basket.TotalPrice());
PaperBasket paperBasket = new PaperBasket(100, 1.5);
Console.WriteLine(paperBasket.TotalPrice());
}
}
public interface IBasket
{
int Count { get; set; }
double Price { get; set; }
public double TotalPrice() => Count * Price;
}
public class BookBasket : IBasket
{
// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/constructors
public BookBasket(int count) => Count = count;
public BookBasket(int count, double price)
{
Count = count;
Price = price;
}
public int Count { get; set; }
public double Price { get; set; }
}
public class PaperBasket : IBasket
{
// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/constructors
public PaperBasket(int count) => Count = count;
public PaperBasket(int count, double price)
{
Count = count;
Price = price;
}
public int Count { get; set; }
public double Price { get; set; }
public double TotalPrice() => Count * Price;
}
public interface ILogger
{
void Log(LogLevel level, string message);
virtual void Log(Exception exception) => Log(LogLevel.Error, exception.ToString());
}
public enum LogLevel
{
Error = 0,
Debug = 1,
Info = 2
}
public class ConsoleLogger : ILogger
{
public void Log(LogLevel level, string message)
{
Console.WriteLine(message);
}
}
public class TelemetryLogger : ILogger
{
public void Log(LogLevel level, string message)
{
Console.WriteLine(message);
}
public void Log(Exception exception)
{
Console.WriteLine("Exception Logger");
}
}
public abstract class Telemetry : ILogger
{
public void Log(LogLevel level, string message)
{
Console.WriteLine($"{level} - {message}");
}
}
}