473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Question regarding a container of objects


Hi,

assuming i have a container of objects, for example:

Course contains a list of CourseOffer which itself is a container of
duration objects

And assuming CourseOffer only contained by Course

i wonder what do you think is a better way to implement it
Course* c=GetCourse();
CourseOffer* cf=new CourseOffer(.....);
cf->AddDuration(10,12);
cf->AddDuration(16,20);
c->Add(cf);
:
:

or

Course* c=GetCourse();
CourseOffer* cf=c.CreateCourseOffer(....);
cf->AddDuration(10,12);
cf->AddDuration(16,20);

I'll go for the second since course control the creation and lifetime
of a course offer

Thanks in advance.

Oct 23 '06 #1
2 1050
tomix wrote:
assuming i have a container of objects, for example:

Course contains a list of CourseOffer which itself is a container of
duration objects

And assuming CourseOffer only contained by Course

i wonder what do you think is a better way to implement it
Course* c=GetCourse();
CourseOffer* cf=new CourseOffer(.....);
cf->AddDuration(10,12);
cf->AddDuration(16,20);
c->Add(cf);
>>

or

Course* c=GetCourse();
CourseOffer* cf=c.CreateCourseOffer(....);
cf->AddDuration(10,12);
cf->AddDuration(16,20);

I'll go for the second since course control the creation and lifetime
of a course offer

Thanks in advance.
If 'CourseOffer' has to be public, then yes, the latter choice is better.
But if 'CourseOffer' is just an implementation detail of 'Course', then
you could simply add the proper interface to 'Course'...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 23 '06 #2
"tomix" <to*****@hotmail.comwrote:
Hi,

assuming i have a container of objects, for example:

Course contains a list of CourseOffer which itself is a container of
duration objects

And assuming CourseOffer only contained by Course

i wonder what do you think is a better way to implement it
Course* c=GetCourse();
CourseOffer* cf=new CourseOffer(.....);
cf->AddDuration(10,12);
cf->AddDuration(16,20);
c->Add(cf);
:
:

or

Course* c=GetCourse();
CourseOffer* cf=c.CreateCourseOffer(....);
cf->AddDuration(10,12);
cf->AddDuration(16,20);

I'll go for the second since course control the creation and lifetime
of a course offer

Thanks in advance.
I generally go for either completely private, or generally extensible.
This means either option one above (which allows us to provide
sub-classes of CourseOffer to a Course,) or make it so the user of
Course need know nothing at all about the CourseOffer class.

--
To send me email, put "sheltie" in the subject.
Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff Williams | last post by:
Ok, everyone loves to talk about dynamic arrays and ptr's etc, they provide endless conversation :) so here goes: Will this leak memory (my intuition says yes): void foo(vector<int*>& vec) {...
3
by: kaede | last post by:
Hi all, Consider the following code fragment: // some data structure class Data { ... } // Container for the data structure Class Container {
8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
1
by: Tim Conkling | last post by:
I've run into a problem with a game I'm designing -- I (think) I need to do something ugly, for speed reasons, and I'm wondering if people here might have any ideas about how solve my problem more...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
9
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new...
16
by: Jeroen | last post by:
Hi all, I have a question which is illustrated by the following piece of code: template <class T> class A { T my_value; }; In a list, I'd like to store pointers to objects of class A....
16
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.