Skip to main content

Creating a Data Type

We may very well want to reuse our method for displaying Length values in classes other than Film and maybe even in applications other than Cinema. In order to make this easy and to more fully take advantage of Caché's support for object-oriented programming, we will define a new datatype called Duration. This datatype will inherit of all of %IntegerOpens in a new tab's behavior, but will modify %IntegerOpens in a new tab's default display format. Our Length property will then be of type Duration rather than %IntegerOpens in a new tab.

So, inside Duration we will override %IntegerOpens in a new tab's LogicalToDisplay method to provide the display format that we want for Length values. When we add Length (as type Duration) to Film, the LengthLogicalToDisplay method Caché automatically adds to Film will display Length values using our custom format rather than %IntegerOpens in a new tab's default format. In the future we will be free to add Duration properties to our classes whenever we want this customized display.

FeedbackOpens in a new tab