472,356 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Class design...

I'm hoping this isn't too off topic, but I'm not sure if I've included some
of my member functions in the right class. I needed to develop numerous
functions to help define object A. These functions currently exist in the
class definition for object A. The thing is, there is another object (B)
who's job it is to call these functions when the app starts up, defining all
possibilities for object A's, then allow future object A's to look up its
attributes from object B without having to re-compute them all over again.
This is a big cost savings. Now realizing that the functions mentioned
above only get called by object B (once), shouldn't they be defined in
object B? Or is this one of those 'same difference' kind of things?

d
Jul 23 '05 #1
3 1213
deancoo wrote:
I'm hoping this isn't too off topic, but I'm not sure if I've included some
of my member functions in the right class. I needed to develop numerous
functions to help define object A. These functions currently exist in the
class definition for object A. The thing is, there is another object (B)
who's job it is to call these functions when the app starts up, defining all
possibilities for object A's, then allow future object A's to look up its
attributes from object B without having to re-compute them all over again.
This is a big cost savings. Now realizing that the functions mentioned
above only get called by object B (once), shouldn't they be defined in
object B? Or is this one of those 'same difference' kind of things?


It seems that the functions you're talking about are part of some kind of
initialisation process and really don't belong to any class, except, maybe
the one that uses them. Now, it would seem that some kind of A's static
initialiser is what you need. Without knowing more of your model, it is
rather impossible to be sure, but have you tried

class A {
class A_initialiser {
public:
A_initialiser() { // do all the stuff here
}
};

static A_initialiser a_init;
public:
// blah blah
};

A::A_initialiser A::a_init; // definition

Now, you could either rely on the initialisation of this static data
member of the class A (like above), or have your B do

class B {
// blah
void initialise_A() {
static A_initialiser a_init; // need to make that class
// A_initialiser public in A or make
// B a friend of A
}
};

which will allow you to control the time (or the event) of the A's class-
wide initialisation.

V
Jul 23 '05 #2
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:bX*******************@newsread1.mlpsca01.us.t o.verio.net...
deancoo wrote:
I'm hoping this isn't too off topic, but I'm not sure if I've included
some of my member functions in the right class. I needed to develop
numerous functions to help define object A. These functions currently
exist in the class definition for object A. The thing is, there is
another object (B) who's job it is to call these functions when the app
starts up, defining all possibilities for object A's, then allow future
object A's to look up its attributes from object B without having to
re-compute them all over again. This is a big cost savings. Now
realizing that the functions mentioned above only get called by object B
(once), shouldn't they be defined in object B? Or is this one of those
'same difference' kind of things?


It seems that the functions you're talking about are part of some kind of
initialisation process and really don't belong to any class, except, maybe
the one that uses them. Now, it would seem that some kind of A's static
initialiser is what you need. Without knowing more of your model, it is
rather impossible to be sure, but have you tried

class A {
class A_initialiser {
public:
A_initialiser() { // do all the stuff here
}
};

static A_initialiser a_init;
public:
// blah blah
};

A::A_initialiser A::a_init; // definition

Now, you could either rely on the initialisation of this static data
member of the class A (like above), or have your B do

class B {
// blah
void initialise_A() {
static A_initialiser a_init; // need to make that class
// A_initialiser public in A or make
// B a friend of A
}
};

which will allow you to control the time (or the event) of the A's class-
wide initialisation.

V


Hmmm, interesting. So after you do a 'class wide' initialization, what
happens to a new instance of the class?
Jul 23 '05 #3
"deancoo" <s2*******@yahoo.ca> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:bX*******************@newsread1.mlpsca01.us.t o.verio.net...
deancoo wrote:
I'm hoping this isn't too off topic, but I'm not sure if I've included
some of my member functions in the right class. I needed to develop
numerous functions to help define object A. These functions currently
exist in the class definition for object A. The thing is, there is
another object (B) who's job it is to call these functions when the app
starts up, defining all possibilities for object A's, then allow future
object A's to look up its attributes from object B without having to
re-compute them all over again. This is a big cost savings. Now
realizing that the functions mentioned above only get called by object B
(once), shouldn't they be defined in object B? Or is this one of those
'same difference' kind of things?


It seems that the functions you're talking about are part of some kind of
initialisation process and really don't belong to any class, except,
maybe
the one that uses them. Now, it would seem that some kind of A's static
initialiser is what you need. Without knowing more of your model, it is
rather impossible to be sure, but have you tried

class A {
class A_initialiser {
public:
A_initialiser() { // do all the stuff here
}
};

static A_initialiser a_init;
public:
// blah blah
};

A::A_initialiser A::a_init; // definition

Now, you could either rely on the initialisation of this static data
member of the class A (like above), or have your B do

class B {
// blah
void initialise_A() {
static A_initialiser a_init; // need to make that class
// A_initialiser public in A or make
// B a friend of A
}
};

which will allow you to control the time (or the event) of the A's class-
wide initialisation.

V


Hmmm, interesting. So after you do a 'class wide' initialization, what
happens to a new instance of the class?


Didn't you say that every instance of the class is supposed to use the
values resulted from the initialisation. So, every instance accesses
the values in 'a_init' and consumes them as needed.

V
Jul 23 '05 #4

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

Similar topics

17
by: Aguilar, James | last post by:
My previous example used the concept of a Shape class heirarchy, so I will continue with that. Suppose I have something like fifty different shapes, and I am trying to instantiate one of them. ...
15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
3
by: fernandez.dan | last post by:
I'm still learning how to use Object Oriented concepts. I'm have a basic question dealing with design. I have two classes that deal with I/O pertaining to network and usb that inherit from an...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
3
by: Trammel | last post by:
Hi, I recently upgraded to VB.net from VB6.. and woah... I feel lost :¬O One of my reasons for upgrading is I was told that VB.net can do class inheritance and subclassing easier. ...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
25
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
5
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the...
6
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.