Q
代碼實現爲班圖
2
A
回答
3
金剛石是組合物(也稱爲聚集),或一個has-a
關係。箭頭是繼承關係,或者是is-a
關係。該行是一個協會。這導致了一個問題:組合和協會有什麼區別。答案是組成更強,通常擁有另一個對象。如果主對象被銷燬,它也將銷燬其組成對象,但不會銷燬它的關聯對象。
在你的榜樣,設施包含(具有-A)LoanInvestment和LoanInvestment繼承的(是-A)投資
這裏是class diagrams using UML一個很好的說明。
這裏是C++中的代碼示例,我不知道C#的不夠好,和Id可能搞砸了:)
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
};
相關問題
- 1. 實現代碼
- 2. 將PHP代碼實現爲函數
- 3. 在實現代碼如下
- 4. openmp的代碼實現
- 5. 實現代碼問題
- 6. C實現nasm代碼
- 7. 實現代碼高亮
- 8. 如何實現代碼
- 9. 如何實現此代碼?
- 10. 實現d3 Codeflower源代碼
- 11. Firebase離子代碼實現
- 12. 如何實現代碼
- 13. 實現代碼到smarty
- 14. 的實現代碼如下
- 15. 在'R'中實現代碼?
- 16. C2DM實現PHP代碼
- 17. JDK本機代碼實現
- 18. 通過現有代碼實現線程
- 19. 通過代碼實現Segue實施
- 20. 試圖將僞代碼轉換爲MERGE SORT的實際代碼
- 21. 代碼的替代實現方式
- 22. 如何將CGContext實現爲實際代碼?
- 23. 計算一個班級在代碼中出現的次數
- 24. 操場上的Swift代碼與實際班級
- 25. 西班牙語的形態學實現
- 26. 代碼閱讀:爲什麼下面的代碼是這樣實現的?
- 27. 通過T4代碼生成實現自動INotifyPropertyChanged實現?
- 28. 代碼優先EF6未取回班級
- 29. 免費源代碼西班牙文版
- 30. 帶班探險Perl代碼編輯器
順便說一句,你是怎麼用它來生成這個UML圖?我見過其他用戶使用yuml.me,這非常酷。 – Brady
yuml.me不是免費的,如果我是對的!我相信那裏有免費的。但這是我會考慮的一個選項。感謝您的建議。 – Pingpong
你在這篇文章中使用了哪些工具? – Brady