我最近建模了一个基本上涉及关联的UML图。比方说,代码是:从UML实现数据库
public class Seller{
private int idSeller;
private String name;
private String passw;
private List<Phone> phones = new ArrayList<Phone>();
public Seller() {
}
public Seller(int idSeller, String name, String passw, List<Phone>phones) {
super();
this.idSeller = idSeller;
this.name = name;
this.passw = passw;
this.phones = phones;
}
//getters and setters
}
和
public class Phone {
private int idPhone;
private String description;
private String number; //will have some chars in it
public Phone() {
}
public Phone(int idPhone, String description, String number) {
super();
this.idPhone = idPhone;
this.description = description;
this.number = number;
}
//getters and setters
}
我不想限制手机卖家可以拥有的数字,而且这仅仅是我的整个代码摘录。
现在,我需要创建我的SQLite数据库并在其中插入数据,但我对如何表示从UML到数据库的关联有点困惑。
如果我没有使用OO,我会在电话表中放入一个指向拥有电话的卖家ID的外键,但是OO的概念让我怀疑这是在这里做的正确方法。
我对UML有很好的理解,但这是我第一次尝试实现UML图并从数据库加载数据。有人能帮我说什么是正确的做法吗?
两个downvotes和没有解释。有人可以告诉我什么是错的,所以? – Math 2013-05-08 18:52:17
您将需要数据库表之间的外键。你刚刚经历了对象关系阻抗http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch – 2013-05-08 19:01:56
我喜欢这个术语“对象 - 关系阻抗”,它代表了我发生的事情。谢谢。 – Math 2013-05-08 19:12:22