How to represent a chunk of Constant Data

A

AdamJoe1

In my application I have a Connection class which has, amongst others,
attributes which represent a host id and port number. These must be unique
for each Connection. I want these attributes to be initialised to values
given by the constructor's parameters. I know in advance how many Connection
classes I need and what the values of these attributes will be. The
Connection class instances are created at various points during the
intialisation phase of the application. I want to hold, in one place, all
the possible values of host id and port number that the application can use.
This way, whenever the need for another Connection instance arises, a new
value can just be added to the list. I was thinking of a ConnectionDetails
class could do this but I'm not sure how best to implement it. It may be
that it will just contain constant data or enums. I don't want to have a
header file full of #defines that I include all over the place. Can anyone
help?
 
D

David Rubin

AdamJoe1 said:
In my application I have a Connection class which has, amongst others,
attributes which represent a host id and port number. These must be unique
for each Connection. I want these attributes to be initialised to values
given by the constructor's parameters. I know in advance how many Connection
classes I need and what the values of these attributes will be. The
Connection class instances are created at various points during the
intialisation phase of the application. I want to hold, in one place, all
the possible values of host id and port number that the application can use.
This way, whenever the need for another Connection instance arises, a new
value can just be added to the list. I was thinking of a ConnectionDetails
class could do this but I'm not sure how best to implement it. It may be
that it will just contain constant data or enums. I don't want to have a
header file full of #defines that I include all over the place. Can anyone
help?

Perhaps you want to hold unused Connection instances in a freelist. This
way, you can create the Connections (all at once?) in one place, and you
don't have to worry about spreading the various Connection attribute
details around your code. You just ask for the next available Connection.

/david
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top