-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrc.com.solid.ISP.java
108 lines (88 loc) · 1.58 KB
/
src.com.solid.ISP.java
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
package com.solid.ISP;
class Document
{
}
interface Machine
{
void print(Document d);
void fax(Document d) throws Exception;
void scan(Document d) throws Exception;
}
// ok if you need a multifunction machine
class MultiFunctionPrinter implements Machine
{
public void print(Document d)
{
//
}
public void fax(Document d)
{
//
}
public void scan(Document d)
{
//
}
}
class OldFashionedPrinter implements Machine
{
public void print(Document d)
{
// yep
}
public void fax(Document d) throws Exception
{
throw new Exception();
}
public void scan(Document d) throws Exception
{
throw new Exception();
}
}
interface Printer
{
void Print(Document d) throws Exception;
}
interface IScanner
{
void Scan(Document d) throws Exception;
}
class JustAPrinter implements Printer
{
public void Print(Document d)
{
}
}
class Photocopier implements Printer, IScanner
{
public void Print(Document d) throws Exception
{
throw new Exception();
}
public void Scan(Document d) throws Exception
{
throw new Exception();
}
}
interface MultiFunctionDevice extends Printer, IScanner //
{
}
class MultiFunctionMachine implements MultiFunctionDevice
{
// compose this out of several modules
private Printer printer;
private IScanner scanner;
public MultiFunctionMachine(Printer printer, IScanner scanner)
{
this.printer = printer;
this.scanner = scanner;
}
public void Print(Document d) throws Exception
{
printer.Print(d);
}
public void Scan(Document d) throws Exception
{
scanner.Scan(d);
}
}