By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,795 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,795 IT Pros & Developers. It's quick & easy.

Design problem

P: n/a
Hi.
I have 3 objects. Object INTERFACEDAT will interact with plain text
files and retrieve some kind of recordset/collection, a FIELDS object,
which will be populated with FIELD objects. From the main module I
want to retrieve a collection of FIELDS so I need to include the 3
classes. This seems good because main needs to know these 3 classes.
But how can avoid, for example, creating an instance of FIELDS
directly in main module, I mean, I want only INTERFACEDAT to create
this kind of object. The same applies to FIELD object. How can I
restrict the creation of these to objects to INTERFACEDAT, how can
avoid from main doing this (field* f = new field;)?
Thank you in advance

Juan Pablo Polotto
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Juan Pablo wrote:

Hi.
I have 3 objects. Object INTERFACEDAT will interact with plain text
files and retrieve some kind of recordset/collection, a FIELDS object,
which will be populated with FIELD objects. From the main module I
want to retrieve a collection of FIELDS so I need to include the 3
classes. This seems good because main needs to know these 3 classes.
But how can avoid, for example, creating an instance of FIELDS
directly in main module, I mean, I want only INTERFACEDAT to create
this kind of object. The same applies to FIELD object. How can I
restrict the creation of these to objects to INTERFACEDAT, how can
avoid from main doing this (field* f = new field;)?
Thank you in advance


By making the constructor of FIELD private or protected.
Nobody can then create an object of that class type, except
an INTERFACEDAT object, which you declare to be a friend of FIELD.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

P: n/a

"Juan Pablo" <ju*********@hotmail.com> wrote in message
news:8b**************************@posting.google.c om...
Hi.
I have 3 objects. Object INTERFACEDAT will interact with plain text
files and retrieve some kind of recordset/collection, a FIELDS object,
which will be populated with FIELD objects. From the main module I
want to retrieve a collection of FIELDS so I need to include the 3
classes. This seems good because main needs to know these 3 classes.
But how can avoid, for example, creating an instance of FIELDS
directly in main module, I mean, I want only INTERFACEDAT to create
this kind of object. The same applies to FIELD object. How can I
restrict the creation of these to objects to INTERFACEDAT, how can
avoid from main doing this (field* f = new field;)?


If you really want to restrict it, with code, then you can make the
constructor private. Then you can make INTERFACEDAT a friend of FIELD.
Jul 22 '05 #3

P: n/a
Karl Heinz Buchegger <kb******@gascad.at> wrote in message news:<3F***************@gascad.at>...
Juan Pablo wrote:

Hi.
I have 3 objects. Object INTERFACEDAT will interact with plain text
files and retrieve some kind of recordset/collection, a FIELDS object,
which will be populated with FIELD objects. From the main module I
want to retrieve a collection of FIELDS so I need to include the 3
classes. This seems good because main needs to know these 3 classes.
But how can avoid, for example, creating an instance of FIELDS
directly in main module, I mean, I want only INTERFACEDAT to create
this kind of object. The same applies to FIELD object. How can I
restrict the creation of these to objects to INTERFACEDAT, how can
avoid from main doing this (field* f = new field;)?
Thank you in advance


By making the constructor of FIELD private or protected.
Nobody can then create an object of that class type, except
an INTERFACEDAT object, which you declare to be a friend of FIELD.


Thank you all for your quick responses.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.