by Conrad Weisert
October 2, 2013
© 2013 Information Disciplines, Inc.
Over a decade ago we noted that different kinds of object-oriented class demand entirely different approaches to design. We tried to explain the distinctions in terms of the structure of the objects, i.e. the member data items. But the popular object-oriented languages then1 provided a single set of tools for defining a class, so the designer had to choose appropriate options and sometimes improvise creative work-arounds.
With the coming of C# the programming language itself presents a workable way of making some of those distinctions explicit. Bill Wagner2 explains:
"Value types store values, and reference types define behavior."—p. 107
"Value types . . . are suited to storing the data that your application manipulates."—p.104
C# provides distinct keywords to introduce those definitions:
structintroduces the definition of a value type.
classintroduces the definition of a reference type.
It follows that
Book from 2007
Note that my own 2007 book Object-Oriented Computation in C++ and Java is easily applied to C#. But just about all the examples should then be struct.—CW
Most value-type data items are known to the application users. They are (or should have been) identified and defined in the systems analysis phase of a project, well before programming begins.
On the other hand programmers use class in C# to introduce the definitions of:
There are exceptions, but C# and Mr. Wagner have given us a sensible way of keeping different concepts separate.
Return to Technical articles
IDI Home page
Last modified October 2, 2013