Browse files

Introduction of Integer Base Class

This is one of the very few examples of a base class without an interface.
The reasons behind this can be found on and the Fluent Types. For now the key points are - This prevents encapsulation violation by requiring a hard cast. No easy to miss method calls.
Sometimes we need the data out, for 3rd party or for sending outside our code. This stucture of an implicit cast allows us to do so without providing methods to violate encapsulation. Using this style will make it very obvious that a primitive is being extracted because there's a hard cast to that primitive type.
  • Loading branch information...
Fyzxs committed Jun 15, 2018
1 parent f66e192 commit 191db71c1f0c52a1a4664916d7645c48df40dc6f
Showing with 6 additions and 0 deletions.
  1. +6 −0 AddTwoInts/AddTwoIntsTests.cs
@@ -22,6 +22,12 @@ public void ShouldReturnSumOfTwoInts()

public abstract class Integer
public static implicit operator int(Integer origin) => origin.Value();
protected abstract int Value();

public class Sum : ISum
private readonly int _augend;

0 comments on commit 191db71

Please sign in to comment.