Lets say A, B are classes then what does this UML diagram mean?
(1) A contains B
Or
(2) B contains A
I'm confused as to which direction the aggregation holds.
Lets say A, B are classes then what does this UML diagram mean?
(1) A contains B
Or
(2) B contains A
I'm confused as to which direction the aggregation holds.
In both cases the class closest to the diamond is the one that contains the class farthest from it. The relationship indicates either a single contained object or a collection of them. Usually it is indicated graphically with a legend similar to the one used in database ERM diagrams: "1..1", "1..m", etc.
The filled diamond means composition. The contained objects has little or no use outside the container and perhaps the container is incomplete without them (or is in an invalid/unstable state without them). For example, every iPhone has a touch screen panel (the transparent thing with a flat cable attached to the side). The touch screen panel separated from the iPhone is not of much use. You don't see people carrying in their pockets detached touch screen panels with the flat cable hanging out.
The empty diamond means aggregation. The contained object can exist separatelly from the container and is useful outside the container. The container can live without the contained object. A keychain is a composite object with a lot of keys attached to it, the keys, laser pointers and can openers can work by themselves without being attached to a keychain and neither the keychain or the tool (key, etc) is left in an unstable state. You can add and remove this items to the keychain but they can exist by themselves as functional tools. The keychain itself can be empty, and you can't say it is broken because of that.
See also this answer: https://softwareengineering.stackexchange.com/a/336764/61852
This is the sort of thing examples help with.
We have an aggregation of ducks on the pond. At least when it's duck season. The ducks do not contain the pond. Well, they drink from it, but that's a different relationship. Unlike the car and carburetor relationship the pond isn't composed of ducks. The pond doesn't stop being a pond if the ducks leave.
The arrow depicting the direction of the association relationship isn't even required to depict aggregation.
UML comes in many versions at this point and people aren't always faithful to the formal rules so you almost have to treat every class diagram like it has it's own language.
FWIW I'll add the definition from the UML specs on p. 110:
none Indicates that the Property has no aggregation semantics. shared
shared Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
composite Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility for the existence and storage of the composed objects (see the definition of parts in 11.2.3).
Especially the explanation for shared (your example with the hollow diamond) is notable as it says "it has not specific meaning". You should therefore avoid it simply unless you have good reasons to use it in your domain. In the latter case you need an explicit definition of its semantics.