Is it correct, that the strong attribute refers to an object composition, and the weak attribute refers to object aggregation, in terms of UML notation?
Is it correct, that the strong attribute refers to an object composition, and the
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Interesting question.
I would say they are similar but different.
In Objective-C the raison d’être for weak references is usually described as a way to manually break what would otherwise be a retain cycle – this is needed as ARC does not (at least currently) support collecting such cycles. This is not really a use of aggregation.
You will also see them used for things like notifications where one object will send notifications to another as long as the latter exists. This might be seen as closer to aggregation, but is really “do something if the target exists” and not “don’t kill the target if I die”.
You can of course use weak references in Obj-C to implement an aggregation, but you might not get exactly the behaviour you expect.
Consider the C++ example from your reference:
Which in Objective-C might be:
When the C++ object is destroyed the array is also destroyed but the elements of the array are not. However in Objective-C the array is not destroyed either – an
NSArrayalways maintains strong references to its members, so they stay around. You could of course design weak collections for Objective-C.