MVC-Planning Poker – Architecture versus unit testing fast
Now I have arrived to the moment when I want data to be persisted on disk. I choose SqlIte – because EF 7 is not yet on the market and SqlIte could work on Windows Phone / Android.
So now I want to just serialize TableData and save . To serialize I have several options – yesterday was XML, not it is Json. The Newtosnoft Json library could do the serialization – and with SqlIte I could put into a database file.
However, the problem is with what we have for serialization / deserialization and how we have conceived the software.
For example, Table class does not have a public constructor – a Table does not exists without a Moderator to create it – and which Cards to display
internal Table(string moderatorName, List<Card> cards = null)
For Deserializer to work, the Table either should have a public constructor
p
public Table(): this("", null)
, either the deserializer will have a function to construct the Table.
The first option means that the architecture will be somehow not so good.
The second option means more work for the programmer.
In .NET we have the third option – we can use obsolete:
[Obsolete("Use CreateTable from TableFactory",true)] public Table(): this("", null)
The true option means raising an error when we COMPILE code that uses the constructor – not at run time, when the deserializer uses it.
So we maintain the architecture – and not enforce at run time.
If we wrote
Table t = new Table();
the compiler gives
1>D:\sourcecontrol\Vs\MVC Planning Poker\PlanningPoker2013\PPTest2013\SerializeTableData.cs(68,23,68,34): error CS0619: ‘Table.Table()’ is obsolete: ‘Use CreateTable from TableFactory’
However , the serialization uses happily the constructor – even if it is obsolete , it works!