In an application, that allows registered users to create pages which can be edited by other registered users, what is the correct way of distinguishing a normal user from the creator of the page, both in UML and SQL.
In UML, I have
-------- accesible by --------
| Page | ------------ |User |
-------- --------
|created by / \
| |
| |
--------- is a |
|Creator|------------------
---------
Now, I don’t think this is the correct UML. So, what would be the correct UML representation of what I am trying to express. And eventually, I would like to create SQL database for the same. In that case, what would the Database Schema look like?
As always you have multiple possibilities – for Model (UML) and Code (SQL, or whatever).
Model A) like you depicted above
Model B) Only a User class, no Creator. User is target of both associations from Page: ‘accessible by’ and ‘created by’
The difference between the models is that you can distinguish between users who can create pages and those who cannot in Model A. Model B only allows to distinguish users who already have created pages and those who have not.
Both models might be implemented by both implementations.
Code 1) Use 5 tables: Page, User, Creator, PageToUser, PageToCreator
Code 2) Use 4 tables: Page, User, PageToUserAccessible, PageToUserCreated (and possibly a flag ‘creator’ in User)
Code 3) Use 3 tables: Page, User, PageToUser and a flag “created” in PageToUser (plus possibly a flag “creator” in User)
Got it? Everything is ‘correct’ – It’s up to you 🙂