0

Having a discussion with my lead pertaining to a code review and I was trying to explain my point of view, when I used the term "aggregate."

Evidently, we think that term is defined different ways.

I Googled it up, and all I can really find is: https://en.wikipedia.org/wiki/Object_composition#Aggregation

but that does not define what the aggregate is.

In the following code, which class is the aggregate and what would you call the other?

class A { }; class B { std::vector<A> m_data; }; 

I thought A is the "aggregate" He thinks B is the "aggregate"

I don't want to go through life misusing terms!

5
  • If you want to know about a C++ feature, cppreference should be the first place you check: en.cppreference.com/w/cpp/language/aggregate_initialization Commented Nov 12, 2019 at 21:50
  • @NathanOliver-ReinstateMonica I am pretty sure (but not 100%) that is a separate definition than the one I am looking for. I am looking for the OO definition when talking about class composition. Commented Nov 12, 2019 at 21:54
  • 1
    C++ and OO might not agree and if you're talking aggregates to another C++ programmer they are most likely going to use the C++ definition. Commented Nov 12, 2019 at 21:55
  • You can write a test: std::is_aggregate: en.cppreference.com/w/cpp/types/is_aggregate Commented Nov 12, 2019 at 22:08
  • In OO design, an aggregate is an object that contains one or more other objects. In C++, the definition is a bit complicated, since it keeps changing with versions of the standard, and it appears the committee has gone to town in making the definitions more nuanced with each evolution of the standard. Commented Nov 13, 2019 at 1:30

2 Answers 2

1

In object oriented parlance, the aggregate is the composite object which contains the parts.

For example, https://www.uml-diagrams.org/aggregation.html uses the term in the sentence:

Example below shows Triangle as an aggregate of exactly three line segments (sides).

So for your example, B can be described as an aggregate of A objects, and its A objects are the parts. (Though there might also be other A objects which are not parts at all.)

(As a number of comments and another answer note, the term "aggregate" also has a more specific technical meaning in C++, describing cases when a type can be considered a sequence of its subobjects, with implications for initializing an object of that type using {} braces.)

Sign up to request clarification or add additional context in comments.

Comments

1

According to the C++11 Standard:

An aggregate is an array or a class (Clause [class]) with no user-provided constructors ([class.ctor]), no brace-or-equal-initializers for non-static data members ([class.mem]), no private or protected non-static data members (Clause [class.access]), no base classes (Clause [class.derived]), and no virtual functions ([class.virtual]).

Given that, A is an aggregate type and B is not.
B can be one if you change it to:

class B { public: std::vector<A> m_data; }; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.