Permalink
Browse files

Moving classes into the file system

File layout is something that needs to be as heavily refactored as the code itself to stay in sync and continue to make sense.

Here the Interger and Bool files have been moved into a Library folder and type specific folder.

While IntegerEquality is a Bool type, it has a stronger association with, and is returned from a method of, the Integer class. It belongs with the other Interger functionality.
  • Loading branch information...
Fyzxs committed Jun 20, 2018
1 parent c648673 commit 8ee4e263fea8710130eaa30b803cde1ae7a56a69
@@ -1,3 +1,4 @@
using AddTwoInts.Library.Integers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddTwoInts
@@ -19,55 +20,4 @@ public void ShouldReturnSumOfTwoInts()
Assert.IsTrue(subject.IsEqual(expected), $"Actual <{(int)subject}> was not the same as Expected <{(int)expected}>");
}
}

public abstract class Integer
{
public static implicit operator int(Integer origin) => origin.Value();
protected abstract int Value();
public Bool IsEqual(Integer other) => new IntegerEquality(this, other);
public Integer Add(Integer addend) => new Sum(this, addend);
}

public sealed class IntegerOf : Integer
{
private readonly int _origin;

public IntegerOf(int origin) => _origin = origin;

protected override int Value() => _origin;
}

public sealed class Sum : Integer
{
private readonly int _augend;
private readonly int _addend;

public Sum(int augend, int addend)
{
_augend = augend;
_addend = addend;
}

protected override int Value() => _augend + _addend;
}

public sealed class IntegerEquality : Bool
{
private readonly Integer _lhs;
private readonly Integer _rhs;

public IntegerEquality(Integer lhs, Integer rhs)
{
_lhs = lhs;
_rhs = rhs;
}

protected override bool Value() => (int)_lhs == _rhs;
}

public abstract class Bool
{
public static implicit operator bool(Bool origin) => origin.Value();
protected abstract bool Value();
}
}
@@ -0,0 +1,7 @@
namespace AddTwoInts.Library.Bools {
public abstract class Bool
{
public static implicit operator bool(Bool origin) => origin.Value();
protected abstract bool Value();
}
}
@@ -0,0 +1,11 @@
using AddTwoInts.Library.Bools;

namespace AddTwoInts.Library.Integers {
public abstract class Integer
{
public static implicit operator int(Integer origin) => origin.Value();
protected abstract int Value();
public Bool IsEqual(Integer other) => new IntegerEquality(this, other);
public Integer Add(Integer addend) => new Sum(this, addend);
}
}
@@ -0,0 +1,17 @@
using AddTwoInts.Library.Bools;

namespace AddTwoInts.Library.Integers {
public sealed class IntegerEquality : Bool
{
private readonly Integer _lhs;
private readonly Integer _rhs;

public IntegerEquality(Integer lhs, Integer rhs)
{
_lhs = lhs;
_rhs = rhs;
}

protected override bool Value() => (int)_lhs == _rhs;
}
}
@@ -0,0 +1,10 @@
namespace AddTwoInts.Library.Integers {
public sealed class IntegerOf : Integer
{
private readonly int _origin;

public IntegerOf(int origin) => _origin = origin;

protected override int Value() => _origin;
}
}
@@ -0,0 +1,15 @@
namespace AddTwoInts.Library.Integers {
public sealed class Sum : Integer
{
private readonly int _augend;
private readonly int _addend;

public Sum(int augend, int addend)
{
_augend = augend;
_addend = addend;
}

protected override int Value() => _augend + _addend;
}
}

0 comments on commit 8ee4e26

Please sign in to comment.