Domain model for a notification system

asp.netasp.net-mvcdomain-modelobject-oriented-design

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.

Notification domain model

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.

User has subscription

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:

  • NotificationTypes
  • Notifications
  • Users

Notifications would be each tagged to a NotificationType, and Users would be subscribed to multiple NotificationTypes.

Here's a visual model:

Notification Types:

type name
-----------------------
group
profile

Notifications:

message   | type
-----------------------
message 1 | group
message 2 | group
message 3 | profile
message 4 | profile

Users:

user name  | subscribed types
------------------------------
john smith | group
jane smith | profile
jack smith | profile,group
Related Topic