Design Case Study
While registering customer details, as part of address details, system A asks to enter address type which could be home, work or vacation address.
Every application relies on collection of master data. Some are core to the business and some are required optionally for the business. For example, a set of country is used more or less by all vertical domain systems, but a set of health issues is core to clinical systems in health care domain. "Postal address type" is one such master data used to specify whether the given customer address is his work, home or vacation address in a sales management system which is used to do correspondence with the user or direct visit to the customer place.
Master data should be understandable across system, geography and languages. It is typically a code value. For example, "IN" is the ISO country code value for India. An enterprise system which handles country data should use either this or other country code value so that it makes the system interoperable. The user interface layer resolves this code value to the actual value which might be either English or any other language. This is more important in health care applications, for example, health issue for a patient needs to be persisted as a health standard code since the terms used on one geographical region could not be understandable in another region. Standard codification system helps to resolve this interoperability issue. SNOMED CT, HL7 are examples for codification standard for health care domain. It is important to define data contracts of a service which carry master data item as coded type which contains the code system and code value. It is up to the service consumer to resolve these code values into appropriate description.
There are some master data in the system, based on these, the behavior of the system is driven. Using code system with value makes the implementation logic less readable and logic might not be direct as well. This will end up with inconsistent domain state across the application. Let us take sales management system, the logic to verify a particular address is home or work, the code would be:
if(addressType.CodeSystem == "CodeSystemA" &&
addressType.CodeValue == "Home")
Here, the logic checks whether the code system is "
CodeSystemA" and value is "
Home". Based on this, some behavior is implemented. It is upto the developer to write right hand side literal of code value (here, "
Home") in the above example. Instead, if a library which has these sets of values would enforce the developer to consume only meaningful code values.
- Code readability and maintainability
- Semantic behavior in service implementation
In general, master data for an enterprise system can be divided into three types:
- Finite native master data set
- Finite master data set
- Infinite global master data set
Examples for "Finite native master data set":
- Communication address type - Home, Vacation, Work
- Patient living status - Live, Deceased
- Marital status - Single, Married
Examples for "Finite master data set":
- Country - India, US, UK
- Health Issues - Hepatitis B, Influenza
Examples for "Infinite global master data set":
- Consumer/User maintainable data
Finite native set contains data that are the main factor for system behavior, generally, status fields or fields used in conditional statements. For example, in personal care management system, based on the address type and primary address, the personal carer decides where they meet patient. Unlike finite set or infinite global set, these data sets also need to be there in-memory in addition with physical data store so that it can be directly accessed in the code with underlying language convention.
System.Enum type in .NET enables to provide in-memory data store which:
- Avoids unnecessary physical database calls to fetch code values
- Makes the business logic more semantic and readable than more ironic
- Storage in native and object-oriented format
In the example given in the problem section, create
SysAAddressType enum for address type defined in
CodeSystemA. This will make the code like:
if(addressType == SysAAddressType.Home)
enum types are not recommended to be part of data contract of a service definition as specified in the problem section. Hence, a mapping between code value and respective
enum value is required.
This article is from my original series at http://www.udooz.net/article/6-patterns-for-enterprise-soa-using-wcf.html.