473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Static Variables and Multiple Inheritance

Hi

I am trying to think of an efficient way of implementing a logging
system for a big program. My thoughts are to create a message logging
base class and letting all objects that need logging ability inherit
from this base class along with the other base classes they inherit
from. This should work (not sure how efficient it is though) but I
want to share the data structure that keeps the log messages between
all the classes that's inherited from this base class. (This data
structure will either be written to the disk, displayed using message
boxes or added to a tree view type of class in the main GUI). To do
this, I am thinking to declare the data structure as static, but I'm
not sure if this will do the trick...

Any idea if this will work? If not, a global data structure can
probably do the trick I don't want to do that. Is there maybe a
simpler way of doing this type of thing?

Thanks in advance
Jaco
Aug 11 '08 #1
3 1907
On Aug 11, 9:05*am, Jaco Naude <naude.j...@gmail.comwrote:
Hi

I am trying to think of an efficient way of implementing a logging
system for a big program. My thoughts are to create a message logging
base class and letting all objects that need logging ability inherit
from this base class along with the other base classes they inherit
from. This should work (not sure how efficient it is though) but I
want to share the data structure that keeps the log messages between
all the classes that's inherited from this base class. (This data
structure will either be written to the disk, displayed using message
boxes or added to a tree view type of class in the main GUI). To do
this, I am thinking to declare the data structure as static, but I'm
not sure if this will do the trick...

Any idea if this will work? If not, a global data structure can
probably do the trick I don't want to do that. Is there maybe a
simpler way of doing this type of thing?
Using inheritance may work, but it doesn't follow the "is-a" vs. "has-
a" OO design principle. That is, your classes are not kinds of
loggers; they use a logger. Inheritance represents the former, not the
latter (except for non-public inheritance, but still it's somewhat
misleading to implement "has-a" this way IMHO). Hence, you should
probably either pass a logger instance in via the constructor, which
could be passed all the way to the base class, or use a global,
possibly a singleton. See the chapter on singletons in Alexandrescu's
_Modern C++ Design_ where he dwells on how to implement loggers with
various feature sets, and see the most updated code from that book
here:

http://loki-lib.sourceforge.net/

Cheers! --M
Aug 11 '08 #2
Global access around a structure is usually the most convenient, but
nothing is really great for logging in OO systems. Allow your design
multiple logs accessed, you generally end up wanting it at some
point. If you want one default, just overload with a literal.

namespace log {
template<typename T>
Log(const std::string &whichLog, const T &t);
}

std::stringstream is your friend for impl.

Aug 11 '08 #3
On Aug 11, 3:05 pm, Jaco Naude <naude.j...@gmail.comwrote:
I am trying to think of an efficient way of implementing a
logging system for a big program. My thoughts are to create a
message logging base class and letting all objects that need
logging ability inherit from this base class along with the
other base classes they inherit from. This should work (not
sure how efficient it is though) but I want to share the data
structure that keeps the log messages between all the classes
that's inherited from this base class. (This data structure
will either be written to the disk, displayed using message
boxes or added to a tree view type of class in the main GUI).
To do this, I am thinking to declare the data structure as
static, but I'm not sure if this will do the trick...
It doesn't really make sense, any more than having every class
inherit from a class Object makes sense. Everything is, or
should be "loggable" (including things like int, which can't
derive from a LoggableObject class).
Any idea if this will work? If not, a global data structure
can probably do the trick I don't want to do that. Is there
maybe a simpler way of doing this type of thing?
Logging is a global service, which means at some level, you
always end up with some sort of "global" object. Usually
several, in fact.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Aug 12 '08 #4

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

Similar topics

0
by: Bryan Green | last post by:
So I'm working on a project for a C# class I'm taking, where I need to keep some running totals via static variables. I need three classes for three different types of objects. The base class and...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
9
by: Clint | last post by:
Hey all - Excuse the cross-post ... I'm not sure what the appropriate newsgroup would be for this question. I have a question that I'm not quite sure how to ask. For all I know, I have the...
4
by: Bryan Green | last post by:
So I'm working on a project for a C# class I'm taking, where I need to keep some running totals via static variables. I need three classes for three different types of objects. The base class and...
5
by: Tom Pearson | last post by:
What is the scope of static variable when programming in ASP.NET? For example I have a control class that uses static callbacks so that another window can pass a list of items to it. The control...
8
by: mike | last post by:
Ok, If I have the following code: //main.cpp class Base { public: int static a;
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
0
by: Axter | last post by:
I'm currently working on the following policy base smart pointer: http://code.axter.com/smart_ptr.h Before working on the above code, I read the following links:...
7
by: Sjaakie | last post by:
Hi, I was wondering... If I'd create a (web)application using static methods in both DataLayer and BusinessLayer, could it happen that, in case of multiple concurrent visitors/users, the...
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
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,...
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.