Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a two classes:

  ------------                         ---------------
     X                                       Y
  ------------                         ---------------
                      relation
  ------------    ------------------   ---------------
      A()                                   C()
      B()                             
      D()
      E()
  ------------                         ---------------

I want to inherit just these two functions from X class, where they are defined with the friend access modifier. My class will be:

 ---------------
      Y                                       
 ---------------

 ---------------
    C()
    A()
    D()
 ---------------

Y class uses some functions of X class namely A and D. How can I model this relationship in a UML class diagram?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If the methods of X are instance methods, you can use the association relationship, which is a solid line between the two classes, however this might indicate to the reader of the model that the relationship is bidirectional. If an instance of Y maintains a reference to X in it and X does not maintain any kind of reference to 'Y', you can add the open-ended arrow to the end pointing toward X to add directionality. If Y can't exist without X, you can also consider using aggregation to indicate this.

If the methods of X are static, consider the dependency relationship, represented by a dotted line and open ended arrow from Y to X. This relationship is used Y calls static methods of X or if the functions of Y take X as a parameter but a reference to X is not maintained within an instance of Y.

In your specific case, when you're trying to model the friend relationship in C++, the information that I can find (such as this question on Stack Overflow) seems to suggest that you should annotate the members of X with the <> stereotype. From this point, I'd use either the association or dependency relationship discussed above, based on how Y is accessing X, with association if Y maintains an instance of X and dependency if Y receives instances of X as parameters to functions as they are needed.

share|improve this answer
    
Thanks so much, one last thing which free uml tool compatible with uml 2.0 should I use ? Staruml is not so compatible with uml 2.0. Thanks again –  gveaf Nov 27 '12 at 14:48
    
@user1796528 I can't answer that question. I'd recommend trying Eclipse's Papyrus plugin, though. It supports most of (maybe all) of UML 2.0 and most of SysML as well. –  Thomas Owens Nov 27 '12 at 14:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.