-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaceSegregationPrinciple.cs
More file actions
68 lines (58 loc) · 1.95 KB
/
Copy pathInterfaceSegregationPrinciple.cs
File metadata and controls
68 lines (58 loc) · 1.95 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DesignPrinciple
{
// Interface for scanning functionality
public interface IScanner
{
// Method to scan documents
void Scan();
}
// Interface for printing functionality
public interface IPrinter
{
// Method to print documents
void Print();
}
// Class representing a multi-function printer that implements both IPrinter and IScanner
public class MultiFunctionPrinter : IPrinter, IScanner
{
// Implement the Print method from IPrinter
public void Print() => Console.WriteLine("Printing");
// Implement the Scan method from IScanner
public void Scan() => Console.WriteLine("Scanning");
}
// Class representing a simple printer that only implements IPrinter
public class SimplePrinter : IPrinter
{
// Implement the Print method from IPrinter
public void Print() => Console.WriteLine("Printing");
}
// Class representing a simple scanner that only implements IScanner
public class SimpleScanner : IScanner
{
// Implement the Scan method from IScanner
public void Scan() => Console.WriteLine("Scanning");
}
// Main program class
class InterfaceSegregationPrinciple
{
public static void Run()
{
// Create an instance of MultiFunctionPrinter
MultiFunctionPrinter mfp = new MultiFunctionPrinter();
mfp.Print(); // Output: Printing
mfp.Scan(); // Output: Scanning
// Create an instance of SimplePrinter
SimplePrinter printer = new SimplePrinter();
printer.Print(); // Output: Printing
// Create an instance of SimpleScanner
SimpleScanner scanner = new SimpleScanner();
scanner.Scan(); // Output: Scanning
}
}
}