tags:

views:

253

answers:

3

I have my class structure as follows

add.h has class add that has method int add(int,int) and add.cpp includes add.h and defines method add above

sub.h has class sub that has method int sub(int,int) and sub.cpp includes sub.h and defines method sub

now, main.h has class main and it includes add.h and sub.h; main class also has some print methods to print results;main.cpp uses method add and sub to do calculations

My question is, what is the relationship between class main & class add also class main & class sub. Main.h simply includes add.h and sub.h, so is there any name for this relations. AFAIK It is not inheritance, it is not compositon or aggregation.

+4  A: 

You are mixing up the concepts of C++ compilation and class relationships - the two things really have nothing to do with each other. In the event that you want to model the relationships between the C++ source files, you should use a UML Component Diagram, but few people bother with this.

anon
Then why take up the majority of your question with it? From the description, the classes have no particular relationships, but I'd need to see the code to be sure.
anon
+1  A: 

You have 3 independent classes. main will only use add and sub in its implementation. I don't see any relation between them.

Max
+1  A: 

As Neil says: the source files (and header files) happen to coincide with the classes here. That means that you don't model the relation between a.cpp and a.h: it's the declaration and the definition of class a, and the fact that they're separated is no design issue, merely a compilation artifact.

In general, when a .cpp file includes a .h file not of it's own class, you can say that the .cpp uses what's in the .h. When class a's declaration needs class b's declaration, probably a is aggregating class b.

In this case, I would say that the (plain, one-directional) relation between main and the 'operations' is to be labeled as 'usage'.

Next to that, it's common to give the sub and add classes a common superclass/interface.

xtofl