アップデート 3
以下のグラフ (Eric の ddd 本 p195 より) の記号 (単線、星付きのひし形、および矢印) は何を意味しますか?
説明するコードサンプルをいただければ幸いです。
アップデート 3
以下のグラフ (Eric の ddd 本 p195 より) の記号 (単線、星付きのひし形、および矢印) は何を意味しますか?
説明するコードサンプルをいただければ幸いです。
ひし形は構成 (集約とも呼ばれます)、またはhas-a
関係です。矢印は継承、またはis-a
関係です。ラインはアソシエーションです。それは疑問につながります: コンポジションとアソシエーションの違いは何ですか。そして答えは、構成はより強力で、通常は他のオブジェクトを所有しているということです。メイン オブジェクトが破棄されると、その構成オブジェクトも破棄されますが、関連付けオブジェクトは破棄されません。
あなたの例では、施設には(has-a)LoanInvestmentが含まれており、LoanInvestmentは(is-a)Investmentから継承しています
これは、 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
};