-2

There are two classes:

Class A{
private:
  int data;
public:
  A(B b) {data=b.do_something()}
};

and

Class B{
public:
  int do.something(){.....};
};

An object of Class B helps to make some job to Class A in the constructor or, alternatively, as a local variable in methods. Objects of Class B are never Class A members. How to call such kind of relationship? That is neither Association, nor Aggregation, nor Composition as far as I understand.

  • 1
    `A` uses `B` or, in your specific case, `A` is constructed using `B`. – Peter Sep 08 '19 at 11:29
  • @Peter Is there a common name for such relationship? – maksim_volodin Sep 08 '19 at 11:34
  • @maksim_volodin it's not a relationship *per se*. See below. – Tom Trebicky Sep 08 '19 at 11:46
  • @TomTrebicky Your answer is about the particular C++ feature. My question is about the relationship classification independently of the language. I put only one parameter in the ctr but it can be more `A(B b, C c.....)` as well there may be methods accepting objects as parameters that do not belong to the class members. – maksim_volodin Sep 08 '19 at 11:55
  • 1
    One name for the relationship is "uses". In UML it is termed a "Realisation" (or "realization" for american spellers). As in, a printer is realised using a printer setup, or (describing the relationship in the opposite sense) a printer setup controls the realisation of a printer. Technically, it is also viewed as a type of association. – Peter Sep 08 '19 at 11:57
  • @maksim_volodin you have to be specific. Yet, the answer still stands, what you showed is a *converting constructor*. There is no other specific name for what you are referring to. Methods changing data members are just that. Or possibly setters. – Tom Trebicky Sep 08 '19 at 11:59
  • @Peter It becomes clear if I use not behaviour(methods) but data(fields) of `class B`, for example `A(B b){data=B.b}` if it is still called realization? I always thought about realization as an interface behaviour implementation, denoted as a dot line on UML diagrams. – maksim_volodin Sep 08 '19 at 12:12

3 Answers3

0

A (B b) ... is referred to as a converting constructor. Check this out.

Tom Trebicky
  • 638
  • 1
  • 5
  • 11
0

One term for the relationship is "uses". As in "A uses B" or (more specifically in your example) "Construction of A uses B" or "A is constructed using B".

In UML it is a type of association that is sometimes termed a "Realisation" (or "realization" for american spellers). In the english language, "realisation" has a number of possible dictionary meanings, but the one relevant here is as a noun "the making or being made real". As in, "a printer is realised using a printer setup", or "realisation of a printer uses a printer setup", or (describing the relationship in the opposite sense) a "printer setup controls realisation of a printer".

Peter
  • 35,646
  • 4
  • 32
  • 74
0

Such a relationship is called Dependency, see the link