建模问题:相互依赖的列表,但可以是专门的条目吗?
相信我,在在这里提问之前,我已经对这个问题进行了很多思考,我想我已经找到了解决方案,但我想看看你们在解决我自己的问题之前能想出什么:)
场景:
在该域中,我们有 3 个实体:一家治疗机构、一家美容店和一名员工。 一家美容店可以雇用 0 到多名员工。 现在,一家美容院列出了一份可以为顾客提供的可能治疗方案的清单。 每种治疗都有描述、持续时间和价格。 每个员工都有一个类似的列表,但每个员工都可以专门化每种治疗(不同的价格或持续时间),添加新的治疗或“删除”来自美容店的治疗。
..这对我来说似乎是一个相当普遍的问题,所以我希望有人能想出一些聪明的办法:)
到目前为止,我正在考虑让每个治疗都有一个唯一的ID,然后让员工列表自己插入治疗与商店的 ID 相同。 这些员工待遇将覆盖具有相同 ID 的商店员工待遇。
提前致谢
Trust me, I've put a lot of thought into this problem before asking here, and I think I got a solution, but I'd like to see what you guys can come up with before settling for my own :)
SCENARIO:
In the domain we got 3 entities: A treatment, a beautyshop and an employee. A beautyshop can hire 0 to many employees. Now, a beautysalon has a list of possible treatments it can do for its costumers. Each treatment has a description, a duration and a price. Each employee has a similar list, but each employee can specialize each treatment (different price or duration), add new treatments or "remove" treatments derived from the beautyshop.
.. This seems like a rather common problem to me, so I was hoping someone could come up with something clever :)
So far, Im thinking about letting each treatment have a unique id, and then let the employee list insert treatments by itself which will have the same id as the one from the shop. These employee treatments will then override the shop ones with the same id..
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们是在谈论问题的客观表示还是问题的数据库表示? 如果它是客观表示,那么专门的治疗应该只是通用治疗的子类。
对于问题的关系数据库表示,事情变得有点困难:(
---=
是一对多,=--=
是多对多)。但是我们如何获得美容店提供的护理列表呢? 我们没有。相反,我们从所有美容店员工处获取了一份可用的护理列表。 也就是说,如果一家美容店有 0 名员工,则它不提供任何护理服务。
您可以在
treatment
表中使用空字段来指示特定员工使用默认属性提供此待遇。 如果特定美容店的治疗类型默认值发生变化,则所有治疗都会更新。Are We talking about the objective representation of the problem or about the database representation of the problem? If it's the objective representation, than a specialized treatment should just be a subclass of the generic treatment.
With the relational database representation of the problem, things get a bit harder:
(
---=
is one to many,=--=
is many to many).But how do We get a list of treatments available in a beautyshop? We don't. Instead We get a list of treatments available from all beautyshop employees. That said, if a beautyshop has 0 employees, it serves no treatments.
You might use null fields in
treatment
table to indicate that the particular employee serves this treatment with default properties. If the treatment_type's defaults change for particular beautyshop, then all treatments are updated.我建议通过添加对
Treatment
类的parentTreatment
引用来向Treatments
添加某种继承/专业化机制。 您将拥有一组标准治疗
,每个员工
都可以选择和自定义它们。BeautySalon
不会显式存储任何Treatments
,瞬态且易失的getAvailableTreatments()
方法将迭代关联的Employees< /code> 并聚合每个
Employee
提供的Treatments
的父Treatments
。I would suggest adding some kind of inheritance/specialization mechanism to the
Treatments
by adding aparentTreatment
reference to theTreatment
class. You would have a set of standardTreatments
, and eachEmployee
would be able to select and customize them.The
BeautySalon
s wouldn't explicitly store anyTreatments
, a transient and volatilegetAvailableTreatments()
method would iterate over the associatedEmployees
and aggregate the parentTreatments
of theTreatments
offered by eachEmployee
.为什么同一个ID要进行不同的治疗呢?
我宁愿设置一个“自定义处理”ID。
Why do you want to have different treatments with the same ID?
I'd rather set up a "custom treatment" ID.