3 ms·
If you want to model a user's transactions you can create a List<Transaction> rather than just a List, and then - The compiler will fail to compile your code i
by adrianmsmith 13y ago
If you want to model a user's transactions you can create a List<Transaction> rather than just a List, and then
- The compiler will fail to compile your code if you put anything in the list apart from a Transaction
- The compiler will fail to compile your code if you try to do anything with an object from that list which a Transaction can't do
- It also makes the code more readable as if my function takes a List<Transaction> you know what you can pass to it. Does it take a List<Transaction> or a List<TransactionId>? It's obvious.
- If you try to pass a List<TransactionId> then the compiler won't compile your code. (Otherwise you'll only find out about it at runtime.)
This means a lot fewer fails at run-time.
Which in turn means a lot less time writing (and maintaining) unit tests.