November 2019
Beginner to intermediate
674 pages
15h
English
Such an approach, while more maintainable, still isn't good for unit testing. We cannot simply create a replacement for TReader, as GetNext is not a virtual method. (The same goes for TWriter and WriteOut.) Even if we fix that, the fact remains that creating mock classes (classes used only for testing other classes) by deriving from real implementation is a recipe for trouble. Doing it that way just brings in lots of dependencies and interconnectedness.
A better way is to extract the public interface of a class to an interface and change the code to depend on an interface, not on a class. In this example, both interfaces are intentionally simple, as the following code fragment shows:
type IReader = interface ['{9B32E26A-456F-45D1-A494-B331C7131020}'] ...Read now
Unlock full access