Permalink
Browse files

Enhacing SRP of Fluent Type

After adding the Into method onto the Integer. It's clear this is a behavior. It's
going to be less clear to extract this into it's own object so we leave the method as part
of Integer, but need to assign the behavior into it's own interface.  This allows us to
write into anything w/o knowing it's specific type.
  • Loading branch information...
Fyzxs committed Jun 24, 2018
1 parent a243499 commit f7afc75c193f96aafa015c03415b498638d48ea2
@@ -11,8 +11,8 @@ public class DisplayDataTests
public void ShouldOutputFromInt()
{
IWrite writer = new ConsoleWrite();
Integer integer = new IntegerOf(3);
integer.Into(writer);
IInto value = new IntegerOf(3);
value.Into(writer);
}

[TestMethod]
@@ -22,7 +22,8 @@ public void ShouldTestIntegerWrites()
Integer integer = new IntegerOf(3);
integer.Into(fakeWrite);

Assert.AreEqual((int)integer, fakeWrite.Item);//Duplicate More From AddTwoInts?

Assert.IsTrue(integer.IsEqual(fakeWrite.Item));
}

private class FakeWrite : IWrite
@@ -3,7 +3,7 @@

namespace MicroObjectPrimitives.Library.Integers
{
public abstract class Integer
public abstract class Integer : IInto
{
public static implicit operator int(Integer origin) => origin.Value();
protected abstract int Value();
@@ -0,0 +1,6 @@
namespace MicroObjectPrimitives.Library.Writers {
public interface IInto
{
void Into(IWrite writer);
}
}

0 comments on commit f7afc75

Please sign in to comment.