Hi,
I've written a few apps with NHibernate and I'm just wondering how others model their domain. One example I've had trouble with - which illustrates a larger question I have - is as follows:
I have an app in which users can listen to music. Each Album has a parent. A parent can either be an Artist or something more generic like Broadway Musical (if it's a compilation without an Artist). Since an Artist and Broadway Musical are very different, I decided to create an IAlbumParent interface which they would both implement. However, this creates problems with NHibernate since I have to use an any mapping for Album.Parent. This is a problem since there are a number of restictions on the things an any relationship can do. Moreover, the docs recommend such a relationship. So, how do others solve issues where classes implement an interface and should be treated as similar in a particular context.
A more common situation would be different kinds of products implementing an IProduct interface.
Of course, inheritance is a possibility, but is not always the best architecture.
Thanks for your thoughts.
|