-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathDevices.cs
53 lines (43 loc) · 1.56 KB
/
Devices.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
using System;
namespace ver1
{
public interface IDevice
{
enum State {on, off};
void PowerOn(); // uruchamia urządzenie, zmienia stan na `on`
void PowerOff(); // wyłącza urządzenie, zmienia stan na `off
State GetState(); // zwraca aktualny stan urządzenia
int Counter {get;} // zwraca liczbę charakteryzującą eksploatację urządzenia,
// np. liczbę uruchomień, liczbę wydrukow, liczbę skanów, ...
}
public abstract class BaseDevice : IDevice
{
protected IDevice.State state = IDevice.State.off;
public IDevice.State GetState() => state;
public void PowerOff()
{
state = IDevice.State.off;
Console.WriteLine("... Device is off !");
}
public void PowerOn()
{
state = IDevice.State.on;
Console.WriteLine("Device is on ...");
}
public int Counter { get; private set; } = 0;
}
public interface IPrinter : IDevice
{
/// <summary>
/// Dokument jest drukowany, jeśli urządzenie włączone. W przeciwnym przypadku nic się nie wykonuje
/// </summary>
/// <param name="document">obiekt typu IDocument, różny od `null`</param>
void Print(in IDocument document);
}
public interface IScanner : IDevice
{
// dokument jest skanowany, jeśli urządzenie włączone
// w przeciwnym przypadku nic się dzieje
void Scan(out IDocument document, IDocument.FormatType formatType);
}
}