Welcome! Log In Create A New Profile


Composite Pattern

Posted by vdWestd 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Composite Pattern
October 18, 2010 12:55PM
Is it just me or is there an issue with the solution provided for Question 2 Assignment 1.

The recursive function getNoMails returns the incorrect value. As far as I can see the issue lies with the findChildren function because it doesn't just return the current objects child objects but also the child object's child objects and so on and so.
So there is actually no need to have a recursive function???

Or am I just missing the plot.
Re: Composite Pattern
October 18, 2010 09:52PM
The question asks the following:


It should be possible to count the total number of mails in a mail folder and in a mail. The
total number of mails in a mail folder includes all its mails including its sub mail folders. Of
course, the total number of mails in a mail is 1.

So if you have nested folders a(1), contains b(2), contains c(3) where the number in brackets indicates the number of mails, i.e. leaf nodes in that folder,
Then the counts would be as follows:
* a = 1 + 2 + 3 = 6
* b = 2 + 3 = 5
* c = 3
Re: Composite Pattern
October 19, 2010 02:19PM
Try QObject::children -> I don't think it is recursive.
Re: Composite Pattern
October 19, 2010 10:01PM
The problem is in all the examples they use findChildren recursively, but it already returns all the child items recursively which produces incorrect results.
So with crowns example above it will return 6 + 5 + 3 = 14 for a and not 6
Re: Composite Pattern
October 21, 2010 11:21AM
You're right provided the solution gives the incorrect result.
I also don't like the way that getSender() is implemented for folders ... it makes no sense.
Sorry, only registered users may post in this forum.

Click here to login