6

Creating User-defined Data Structures

6.1 INTRODUCTION AND OBJECTIVES

In this chapter we design and implement a number of data structures that we shall deploy as reusable modules in later applications. We have created these classes because the data structures presented in Chapter 5 do not always have the functionality that we need and it then becomes necessary to develop software modules for a number of important application areas:

  • Specialised data structures that model tables of information (for example, volatility surfaces, cash flows and lookup tables).
  • Creating classes for mathematical vectors and matrices.
  • User-defined generic set classes.
  • Associative arrays and matrices.

We develop these classes by using the .NET functionality and collections that we introduced in Chapter 5. In general, we use composition to hide low-level functionality. We remark that some of the C# classes that we discuss in this chapter are based on the corresponding C++ classes introduced in Duffy 2004a. In general, porting the code from C++ to C# was relatively straightforward.

6.2 DESIGN RATIONALE AND GENERAL GUIDELINES

We give the motivation for the data containers in this chapter. Some of the forces are:

  • Using the generic programming model to create data containers is more suitable than using an object-oriented approach because the underlying data type is generic. Furthermore, it is possible to define constraints on the underlying data types (this is a contract between supplier and consumer). ...

Get C# for Financial Markets now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.