473,545 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ 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 1919
On Aug 11, 9:05*am, Jaco Naude <naude.j...@gma il.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<typena me T>
Log(const std::string &whichLog, const T &t);
}

std::stringstre am is your friend for impl.

Aug 11 '08 #3
On Aug 11, 3:05 pm, Jaco Naude <naude.j...@gma il.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 objektorientier ter Datenverarbeitu ng
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
1303
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 inherited classes are all identical. I need to refer to the static variables in each class, and each must maintain its own values for each static...
22
23323
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 examples?
9
4148
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 verbaige completely wrong, but here goes nothing ... I'm currently using the MS Data Access Block for a desktop application I'm writing. Recently, I...
4
10740
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 inherited classes are all identical. I need to refer to the static variables in each class, and each must maintain its own values for each static...
5
6848
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 doesn't have access to this other object so needs to subscribe to the static callback. As such the static callback then needs to get hold of the real...
8
9547
by: mike | last post by:
Ok, If I have the following code: //main.cpp class Base { public: int static a;
11
3803
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 experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of...
0
1569
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: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1681.pdf http://www.cuj.com/documents/s=8890/cujexp0310alexandr/alexandr.htm I notice the above links only talk about...
7
1950
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 applications throws a sqlexception, because multiple DataReaders (from different methods) try to access the same (static) SqlConnection? TIA
0
7661
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. ...
0
7815
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...
1
7433
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7763
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...
0
5976
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...
1
5340
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...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1891
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
0
712
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.