This is not a book about the theory behind patterns; rather, this book focuses on the aspects of their implementation. Before I scare you all off with all this talk about design patterns, their history, modern advances, anti-patterns, and so on, I have decided to present a very simple pattern using an example. A few lines of code should explain why a pattern—based approach to problem solving can be a good thing.
In the code archive for this chapter, you'll find a simple console application called DesignPatternExample. Inside, you'll find an implementation of a sparse array, as shown in the following code fragment:
type
TSparseRec = record
IsEmpty: boolean;
Value : integer;
end;
TSparseArray = TArray<TSparseRec>;
Each array index can either be empty (in which case IsEmpty will be set to True), or it can contain a value (in which case...