2

Update 3

What do the signs (single line, diamond with star, and arrow) mean in graph (From Eric's ddd book p195) below:

enter image description here

Any code sample to illustrate would be appreciated.

avandeursen
  • 8,458
  • 3
  • 41
  • 51
Pingpong
  • 7,681
  • 21
  • 83
  • 209
  • BTW, what did you use to generate this UML diagram? Ive seen other users use yuml.me, which is very cool. – Brady Jun 03 '12 at 15:11
  • yuml.me is not free, if i am right! I believe there are free out there. But it is an option that I will consider. Thanks for the advice. – Pingpong Jun 03 '12 at 18:50
  • which tool did you use for this post? – Brady Jun 03 '12 at 19:17
  • I didn't create the UML. It is a screenshot from the book. http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_2?ie=UTF8&qid=1338743324&sr=8-2 – Pingpong Jun 03 '12 at 20:10
  • Please refer to this link: http://stackoverflow.com/questions/6657871/free-uml-tool-ideally-for-net – Pingpong Jun 03 '12 at 20:45
  • For anyone who's looking to create UML class diagrams for free, there's a piece of software called software ideas modeller which you can download, it's quite easy to use, and you can create all kinds of other diagrams on it too. – Alex Oct 06 '14 at 13:50

1 Answers1

3

The diamond is composition (also called aggregation), or a has-a relationship. The arrow is inheritance, or an is-a relationship. The line is an Association. That leads to the question: what's the difference between Composition and Association. And the answer is that composition is stronger and usually owns the other object. If the main object is destroyed, it will also destroy its composition objects, but not its association objects.

In your example, a Facility contains a (has-a) LoanInvestment and a LoanInvestment inherits from an (is-a) Investment

Here is an excellent description of class diagrams using UML.

Here's a code example in c++, I dont know c# well enough and Id probably mess it up :)

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
};
Brady
  • 10,207
  • 2
  • 20
  • 59
  • what about the single line between facility and loan? Does the Loan contain a collection of LoanInvestment? – Pingpong Jun 03 '12 at 12:10
  • @Pingpong The additional two lines are not standard UML. Standard UML has a black or white diamond for (has-a or consists-of) and full arrows for is-a. Empty arrows are directional navigation on has-a. – Danny Varod Jun 03 '12 at 12:16
  • @Pingpong, I updated the answer for the single line. I can give you a good code example in c++, would that help? – Brady Jun 03 '12 at 12:17
  • 1
    @Brady Inheritance does not look like that. – Danny Varod Jun 03 '12 at 12:18
  • @DannyVarod, which additional lines are you referring to? typically the aggregation lines indicate how many of each, like "1 0..*" or "1 1..*" – Brady Jun 03 '12 at 12:19
  • @DannyVarod, could it be that I mixed dependency with inheritance, because its not a block arrow? Typically though dependency is a dashed-line, right? But it makes sense that a LoanInvestment inherits from an Investment, right? – Brady Jun 03 '12 at 12:22
  • @DannyVarod, could you elaborate on full arrows, empty arrows, Inheritance that you mentioned, and the meaning for the graph. – Pingpong Jun 03 '12 at 12:32
  • @Pingpong, I think the web page I referenced in the answer has an excellent description of what you're looking for. I summarized it in my answer, but to go into more detail would just be copying said web page. – Brady Jun 03 '12 at 12:35
  • @Brady, should the Loan contain a collection of LoanInvestment, because the star sign on the LocanInvestment? Likewise, for Facility and Investment. – Pingpong Jun 03 '12 at 12:37
  • @Pingpong, That's a good point, but since the UML isnt completely valid, I decided not to, but if it was something like "1 0..*" or "1 1..*" then yes. As it is now, its "1 1" – Brady Jun 03 '12 at 12:44
  • @Brady, according to http://en.wikipedia.org/wiki/Class_diagram#Multiplicity, the 0..star can be star. The signs in the graph above might be 1 to 0..star for both unfilled diamonds. – Pingpong Jun 03 '12 at 13:13
  • @Pingpong, ok, good point, sounds like you're starting to learn it well now :) – Brady Jun 03 '12 at 13:18
  • @Pingpong, I updated the code to allow for the possibility of multiplicity – Brady Jun 03 '12 at 13:29
  • @Brady, an Is-a relationship should be a triangle, rather than the lined arrow head. However, there is no information on that page. But the inheritance between LoanInvestment and Investment make sense to me. Thank you for your advice. – Pingpong Jun 03 '12 at 13:52