I'm trying to build a modular notification service in a ASP.NET MVC web application. The application generates notifications and the service is responsible for delivering the notifications to the right users. When creating a domain model for the notification service, inheritance naturally comes to mind.
One of the requirements for the notification service is that users can be subscribed to particular notification types. For example, User can subscribe to receive NewMessage notifications but not ProfileNotification notifications.
How would one represent a relationship where a User has a Subscription to a notification type, but the notification type is represented through inheritance. Of course, this could be possible via reflection, but I was wondering if there was a domain model that came naturally from my requirements since I couldn't think of one.
I'm using ASP.NET MVC and Entity Framework Code First, but I think the question is general enough for any object oriented programming language.
Best Answer
From your description, it doesn't seem like you need to use inheritance at all - you can do this with a one-to-one and one-to-many relationship.
I would create three objects:
Notifications would be each tagged to a NotificationType, and Users would be subscribed to multiple NotificationTypes.
Here's a visual model: