473,595 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1272
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_initialise r 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.********@com Acast.net> wrote in message
news:bX******** ***********@new sread1.mlpsca01 .us.to.verio.ne t...
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_initialise r 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*******@yaho o.ca> wrote...
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:bX******** ***********@new sread1.mlpsca01 .us.to.verio.ne t...
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_initialise r 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
4798
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. The trick is, the instatiation will be based on a string with the exact same name as the type that I am trying to instantiate. Obviously, writing a fifty element long switch statement is an inferior solution. So, how can I instantiate based on...
15
9051
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 the purpose of learning to work with C++. It therefore makes some sense for me to give the situation the amount of consideration presented below. To be quite honest, I'm amazed at the amount there is to say about such a seemingly simple...
3
1808
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 abstract parent with four basic functions: Open, Read, Write, and Close. // Note alot of the stuff has been left out // just to give a basic picture class IO { public:
9
2216
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 all have a different enumeration in them called Properties. I want to basically have a variable The_Class that I can dynamically point to either Class_A, Class_B, or Class_C and then do The_Class.properties to get the correct enumeration. How...
3
1932
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. Would someone be so kind as to provide a small demo about classes for some
6
2067
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 DeviceManager which is only interested in CD/DVD devices. I want to get the list of CD/DVD devices and "be informed when a disc inserted into a device". I am developing this on Linux. So, I used HAL API and read some system (actually /proc) files to gather...
25
2126
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 if the parameter model_name is "aa", then choose ModelAA. Currently I do this as follows:
6
2129
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 times when I program, I will create objects for a specific purpose for a program and if I need to add to it I just add the code.
5
1726
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 members Y is the location of a file to be read. The original design assumes that this class will be instantiated and each instance will happily mange its own members. (ie One file location per instance...no thread-safety). Now another class A...
6
8149
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 situation where I am implementing base class functions by including a pointer to subclass member in base class. Reason being functionality is common for subclasses but the members are common within subclass only (static member of subclass) but...
0
7957
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8262
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8252
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5421
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3875
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.