Ok, here is an example. I have an application in which many domain objects include an attribute that indicates "Calendar Month" where a particular day of the month is relevant. (December 1998, March 2003, etc.)
So, I created a structure that represents these values within myself as a primitive integer (the number of months since January 2000, I think). This structure includes many methods for creating instances of this CalendarMonth structure from different input types (DateTimes, strings that can be converted to date or time or year in a year, etc. The structure has methods CalendarMonth Parse(string inputValue) and bool TryParse(string inputValue out CalendarMonth calMonth) , as these bits of functionality are used throughout this application.
This structure also encapsulates methods that return dateTime values for the first month, last day of the month, beginning of the month UTC, etc. etc.
It also has many operator overloads, so I can “add / subtract” a time span in a calendar month and get CalendarMonth or subtract two CalendarMonth structures to get TimeSpan ... kind of like datetime. It also has both implicit and explicit cast operator exploits to cast back and forth between datetimes and CalendarMonth structures ...
I would say, in general, this method is useful at any time when you have a Type in your Domain that could be called a value type (in the sense that it does not have an identifier), but it is determined simply by its attribute values, and which has “strong” quantitative properties of behavior in the problem area in which your application lives.
source share