1

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.

1

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
  • I don't quote follow this answer since the question is asking about domain models and you're providing database schema. As a database schema this isn't a very good one anyway. You can tell because of the comma in the subscribed types column. – RibaldEddie Aug 8 '14 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.