473,407 Members | 2,598 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,407 software developers and data experts.

OO Design question: How to pass around very common classes

Hi,

I am making an application that is beginning to turn quite large.
This application has some classes that are known by almost every other class
namely CApplication, CProject and the like.
So far, I have been passing around references to these classes in the
constructors of all the other classes but it is beginning to annoy me to
have to do this.
I could easily make global variables, it wouldn't be unsafe in the sense
that I know that the instances are always present and that there is only
one. Still, this solution not pleasing to the eye :) and I gather there
might turn up some thread safety issues or the like (currently, everything
runs in a single thread) in the future.

Any alternative suggestions would be very welcome.

Søren
Jul 19 '05 #1
1 1387
On Thu, 24 Jul 2003 17:52:07 +0200, "Søren Johansen"
<so***************@hotmail.com> wrote:
Hi,

I am making an application that is beginning to turn quite large.
This application has some classes that are known by almost every other class
namely CApplication, CProject and the like.
So far, I have been passing around references to these classes in the
constructors of all the other classes but it is beginning to annoy me to
have to do this.
I could easily make global variables, it wouldn't be unsafe in the sense
that I know that the instances are always present and that there is only
one. Still, this solution not pleasing to the eye :) and I gather there
might turn up some thread safety issues or the like (currently, everything
runs in a single thread) in the future.

Any alternative suggestions would be very welcome.

Søren


You could make a static member function in the class you need to 'pass
around', like this:

class Application
{
public:
static Application* GetApplicationInstance() { return
s_mpSingleton; }
protected:
static Application* s_mpSingleton;
}; // Application ///

Note that you will need to add code which initializes the pointer,
ensures the object is in fact a singlerton, etc.

</dib>

John Dibling
email: dib@substitute_my_full_last_name_here.com
Witty banter omitted for your protection
Jul 19 '05 #2

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

Similar topics

9
by: Patchwork | last post by:
Hi Everyone, I have a design related question (in C++) that I am hoping someone can help me with. It is related to my previous post but since it was pointed out that I was more or less asking...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
3
by: Amadelle | last post by:
Hi All and thanks in advance, I wanted to know when is a good idea to use a static class (with static constructor) and when to use instance classes? I have read couple of articles on line and...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
13
by: KV | last post by:
I'm new to OO Design, and I'm fixing to start writing my very first C# program. Given the complexity of OO programming, I would like to run something by this group and get general input. My...
4
by: Josh Harris | last post by:
Here is my question: It is common to have many pieces of business logic encapsulated within asp.net user controls. This can be found in high visibility projects such as the iBuySpy portal from...
5
by: Leslaw Bieniasz | last post by:
Hello, I have the following OOP design problem. I have a base class designed as an element of a list, let's say: class A { public: // some stuff
13
by: John Kraft | last post by:
Friends, I'm working on some crud stuff, and I was looking for opinions on the subject. Below, I have pasted some VERY simple sample code. Class2 is a "traditional" crud type object. In a...
1
by: GS | last post by:
I am still a novice in vb .net 2. actually in vb.net period. please bear with me. Problem: I often found myself refereeing to common utility like setStatus and logs on the form, and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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
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...
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.