Skip to content

Commit

Permalink
Refactor: BitTypeValue.Instance, private constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlopez committed Jul 17, 2011
1 parent 45a5a3e commit 129923a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions AjVars.Tests/TypeValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void ShortToAndFromMemory()
[TestMethod]
public void ParseBitTypeValueFromBooleanString()
{
TypeValue type = new BitTypeValue();
TypeValue type = BitTypeValue.Instance;

Assert.AreEqual(false, type.ParseString("false"));
Assert.AreEqual(true, type.ParseString("true"));
Expand All @@ -133,7 +133,7 @@ public void ParseBitTypeValueFromBooleanString()
[TestMethod]
public void ParseBitTypeValueFromZeroOneString()
{
TypeValue type = new BitTypeValue();
TypeValue type = BitTypeValue.Instance;

Assert.AreEqual(false, type.ParseString("0"));
Assert.AreEqual(true, type.ParseString("1"));
Expand All @@ -143,7 +143,7 @@ public void ParseBitTypeValueFromZeroOneString()
public void SetAndGetBitTypeValueUsingMemory()
{
ByteMemory memory = new ByteMemory();
TypeValue type = new BitTypeValue();
TypeValue type = BitTypeValue.Instance;

type.ToMemory(memory, 10, true);
Assert.IsTrue(memory.GetBit(10));
Expand Down
8 changes: 8 additions & 0 deletions AjVars/BitTypeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

public class BitTypeValue : TypeValue
{
private static BitTypeValue instance = new BitTypeValue();

private BitTypeValue()
{
}

public static BitTypeValue Instance { get { return instance; } }

public override object FromMemory(ByteMemory memory, int address)
{
return memory.GetBit(address);
Expand Down
2 changes: 1 addition & 1 deletion AjVars/BitVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class BitVariable : Variable
{
public BitVariable(int address, ByteMemory memory)
: base(address, new BitTypeValue(), memory)
: base(address, BitTypeValue.Instance, memory)
{
}
}
Expand Down

0 comments on commit 129923a

Please sign in to comment.