-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathIsp.cs
54 lines (49 loc) · 1.39 KB
/
Isp.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
namespace Solid.InterfaceSegregation
{
class Isp : IPrinciple
{
public string Principle()
{
return "Interface Segregation";
}
// If we want to add more functionality, don't add to existing
// interfaces, segregate them out.
interface ICustomer // existing
{
void Add();
}
// BAD:
interface ICustomerImproved
{
void Add();
void Read(); // Existing Functionality, BAD
}
// GOOD:
// Just create another interface, that a class can ALSO extend from
interface ICustomerV1 : ICustomer
{
void Read();
}
class CustomerWithRead : ICustomer, ICustomerV1
{
public void Add()
{
var customer = new Customer();
customer.Add(new Database());
}
public void Read()
{
// GOOD: New functionality here!
}
}
// e.g.
void ManipulateCustomers()
{
var database = new Database();
var customer = new Customer();
customer.Add(database); // Old functionality, works fine
var readCustomer = new CustomerWithRead();
readCustomer.Read(); // Good! New functionalty is separate from existing customers
}
}
}