12.4. Non-primitive Data Type Classes

The type of an attribute may be expressed as a non-primitive class in its own right in a domain model. For example, in the POS system there is an item identifier. It is typically viewed as just a number. So should it be represented as a non-primitive class? Apply this guideline:

Represent what may initially be considered a primitive data type (such as a number or string) as a non-primitive class if:

  • It is composed of separate sections.

    • phone number, name of person

  • There are operations usually associated with it, such as parsing or validation.

    • social security number

  • It has other attributes.

    • promotional price could have a start (effective) date and end date

  • It is a quantity with a unit.

    • payment amount has a unit of currency

  • It is an abstraction of one or more types with some of these qualities.

    • item identifier in the sales domain is a generalization of types such as Universal Product Code (UPC) or European Article Number (EAN)


Applying these guidelines to the POS domain model attributes yields the following analysis:

  • The item identifier is an abstraction of various common coding schemes, including UPC-A, UPC-E, and the family of EAN schemes. These numeric coding schemes have subparts identifying the manufacturer, product, country (for EAN), and a check-sum digit for validation. Therefore, there should be a non-primitive ItemID class, because it satisfies many of the guidelines above.

  • The price and amount attributes should be non-primitive Quantity or Money classes because they are quantities in a unit of currency.

  • The address attribute should be a non-primitive Address class because it has separate sections.

The classes ItemID, Address, and Quantity are data types (unique identity of instances is not meaningful) but they are worth considering as separate classes because of their qualities.

Where to Illustrate Data Type Classes?

Should the ItemID class be shown as a separate conceptual class in a domain model? It depends on what you want to emphasize in the diagram. Since ItemID is a data type (unique identity of instances is not important), it may be shown in the attribute compartment of the class box, as shown in Figure 12.4. But since it is a non-primitive class, with its own attributes and associations, it may be interesting to show it as a conceptual class in its own box. There is no correct answer; it depends on how the domain model is being used as a tool of communication, and the significance of the concept in the domain.

Figure 12.4. If the attribute class is a data type, it may be shown in the attribute box.


A domain model is a tool of communication; choices about what is shown should be made with that consideration in mind.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.70.66