/
InterfaceSegregation.cs
58 lines (47 loc) · 1.14 KB
/
InterfaceSegregation.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
using UnityEngine;
namespace SOLIDPrinciples.InterfaceSegregation
{
public class InterfaceSegregation : MonoBehaviour
{
// Clients should not be forced to depend on methods that they do not use.
private void Start()
{
Square square = new Square(10);
Cube cube = new Cube(10);
Debug.Log("Area = " + square.GetArea());
Debug.Log("Volume = " + cube.GetVolume());
}
}
public interface ITwoDimensionalShape
{
float GetArea();
}
public interface IThreeDimensionalShape
{
float GetVolume();
}
public class Square : ITwoDimensionalShape
{
private float _length;
public Square(float length)
{
_length = length;
}
public float GetArea()
{
return Mathf.Pow(_length, 2);
}
}
public class Cube : IThreeDimensionalShape
{
private float _length;
public Cube(float length)
{
_length = length;
}
public float GetVolume()
{
return Mathf.Pow(_length, 3);
}
}
}