数据库+数据模型设计模式 [英] Database + data model design pattern

查看:221
本文介绍了数据库+数据模型设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我们公司设计了一个通知系统,用户可以指定他们是否要为不同的操作发送通知。



我想知道这个Design Patter的名字是什么,所以我可以阅读并遵循do和dont的。 p>

故事(要求):当用户在我们的网站(应用)上执行不同的操作时,操作会发布到他们的Facebook和Twitter帐户,我们也通过电子邮件发送给他。有很多操作,6下Facebook,6下Twitter和12下电子邮件。因此,为每个操作创建一个单独的列没有意义,特别是它们的值默认为true。



因此,例如当用户上传一个新图像他们的网页在我们的网站上,我们要发布到他们的Facebook和Twitter,他们只是上传一个图像到我们的应用程序。



我的设计是一个meta_data表与这些列(带有示例行):

  id,user_id,命名空间,通知,值
0,1, ','image_upload',false
1,1,'twitter','video_post',false
2,10,'email','send_money',false

也可用于所有操作及其命名空间在创建表时,我默认向数据库添加一些行,其中我将所有值设置为true 。
然后在用户设置页面中,他可以看到默认情况下都已选中的这些设置的复选框。
每次用户创建取消选中一个时,我将为该用户创建一个新行,操作和命名空间的值为false。

解决方案

这被称为观察者模式


I'm designing a notification system for our company, where users can specify if they want to send notifications for different actions or not.

I'm wondering what is the name for this Design Patter, so I can read on it and follow the do and dont's.

Story(requirements): When user takes different actions on our site (app), the actions get posted to their facebook and twitter accounts and and we emailed him also. There are a lot of actions, 6 under Facebook, 6 under Twitter and 12 under email. So it doesn't make sense to make a separate column for each action, specially that their value is by default true.

So for example when user uploads a new image to their page on our website we want to post to their facebook and twitter, that they just upload an image to our app.

My desing for this is a meta_data table with these columns (with examples rows):

id, user_id, namespace,  notification,   value 
0,  1,       'facebook', 'image_upload', false
1,  1,       'twitter',  'video_post',   false
2,  10,      'email',    'send_money',   false

also for all the actions and their namespaces I add some rows by default to the database when creating the table, where I set all the values to true. Then in users setting page he can see check-boxes for these settings that are all checked by default. Every time the user creates uncheck one, then I create a new row for that user, action and namespace with the value to be false.

解决方案

This is called Observer pattern.

这篇关于数据库+数据模型设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆