更新3
符号(单行,带有星号和箭头的钻石)在图表中的含义(来自Eric的ddd book p195):
任何可以说明的代码示例都将受到赞赏。
答案 0 :(得分:3)
钻石是组合物(也称为聚合物)或has-a
关系。箭头是继承,或is-a
关系。这条线是一个协会。这导致了一个问题:组合和协会之间的区别是什么。答案是组合更强,通常拥有另一个对象。如果主对象被销毁,它也会破坏它的组合对象,但不会破坏它的关联对象。
在您的示例中,工厂包含(has-a)LoanInvestment和LoanInvestment继承自(is-a)投资
以下是对class diagrams using UML的精彩描述。
这是c ++中的一个代码示例,我不太了解c#,而且我可能会搞砸它。)
class Facility
{
public:
Facility() : loan_(NULL) {}
// Association, weaker than Composition, wont be destroyed with this class
void setLoan(Loan *loan) { loan_ = loan; }
private:
// Composition, owned by this class and will be destroyed with this class
// Defined like this, its a 1 to 1 relationship
LoanInvestment loanInvestment_;
// OR
// One of the following 2 definitions for a multiplicity relation
// The list is simpler, whereas the map would allow faster searches
//std::list<LoanInvestment> loanInvList_;
//std::map<LoanInvestment> loanInvMap_;
Loan *loan_:
// define attributes here: limit
};
class Loan
{
public:
// define attributes here: amount
// define methods here: increase(), decrease()
private:
// 1 to 1 relationship, could consider multiplicity with a list or map
LoanInvestment loanInvestment_;
};
class Investment
{
// define attributes here: investor, percentage
};
class LoanInvestment : public LoanInvestment
{
// define attributes here
};