![]() | |
![]() ![]() |
![]() | Imperfect C++ Practical Solutions for Real-Life Programming By Matthew Wilson |
Table of Contents | |
Chapter 4. Data Encapsulation and Value Types |
4.2. Value Types and Entity TypesFrom a simplistic point of view—this is my own definition—we can characterize value types as things that "are," and entity types as things that "do." Bjarne Stroustrup provides a great definition of value types—he calls them concrete types:[1] "The intent...is to do a single...small thing well and efficiently. [They do not usually] provide facilities to modify [their] behaviour."
Langer and Kreft [Lang2002] provide more detailed definitions. Value types are "types that have content, and whose behaviour depends vitally on this content. For example, two strings behave differently when they have different content, and they behave in the same way (and compare equal) if they have the same content. Their content is their most important feature." They stress that equality is more important than identity, which I think is a very important aspect of the value type concept. Langer and Kreft define entity types as those "whose behaviour...is largely independent of their content. [Their] behaviour is their most important feature." Comparing equality of entity types is generally meaningless. I confess to liking the simplicity of my own definition (a surprise, to be sure!), but the qualification provided in the Langer-Kreft definition is important. The notion of an entity type encompasses a great spectrum of characteristics—at the least it covers concrete types, abstract types, and polymorphic and nonpolymorphic types—but in the context of this chapter I'm considering them as one. Many of these concepts are referenced and some elucidated further later in the book. The remainder of this chapter examines the concept of value types, looking in detail at whether there's a single grade of value type. As is my wont, I'm going to assert that there's not. ![]() |
![]() | |
![]() ![]() |