Developing a domain model to ensure future flexibility is not a trivial task. One of the most common domain problems clients run into is the changing nature of what defines a "user".
As always, while this blog tends towards Java for its examples, problems covered here occur in many languages.
The Common Design Mistake
Let's examine what is typically the first and only design for a user model in an example domain (which is a simplified form of the design I've seen in the last two clients I worked with)
There are a couple of interesting questions already, both of which strike at the very heart of why this is a design mistake.
- What happens when a Partner is also an Advertiser?
- Are Advertiser, Affiliate, and Partner "types of user" or are they "roles played by a user"
- All three user "types" appear to have phoneNumber as an attribute. Assuming not all future users will have this as an attribute, how can the developer simplify this design so as not to repeat commonly used attributes all over the place?
if ( user instanceof Advertiser ) doSomething(); else if ( user instanceof Affiliate ) doSomethingElse(); else if ( user instanceof Partner) doYetAnotherThing();
So much for object-oriented design...
In part 2 of the series, I'll cover a simple object-oriented design solution that allows for future flexibility and gives solid answers to the three questions asked.
No comments:
Post a Comment