473,769 Members | 5,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can use of singletons denote poor project design?

I'm working on a large project(from scratch). The program is
essentially a data file processor, the overall view is this:

A data file is read in, validated and stored in a memory structure
similar to a database or XML representation. Rules to modify the stored
data will be executed, then the data will be transformed into an output
format.

Think something similar to FormatA -> XML -> Manipulate XML -> FormatB

The project is large but so far I have been able to keep it very
modular using OO design. I do however have questions about my use of
singletons for certain aspects of the program.

*
I've found the use of singleton objects quite nice for various aspects
of this program, I do enjoy having the ability to use a singleton class
by using the Class::Instance () syntax, thus removing the need to pass
instances around in all my function calls. Also very useful is the
ability to use a guarenteed single instance by simply including the
header containing my singleton.
Right now I use them for :

Logging server : A central message storage and distribution to N number
of reports/logs)
Program State : Again a central point to keep track of program status.
Central Data representation
I didn't know if the use of multiple singletons could represent a
design flaw and would like some opinions on their use or the use of
multiple singletons in a single project.

I know its vague, but without going into a verbose write-up I don't
know what else might be of value here. If there is a bit of
information I can provide, just ask.

Thank you,
JF

Feb 24 '06
11 2363
I believe some of the contentious points here have come about because
of the reason posted earlier by gottlobfr...@gm ail.com
I doubt you are lazy, (in fact it sounds like your are making extra
effort to use OOP, code separation, etc) but I point out how that
sentence sounds, as something to reflect upon. In fact, if I didn't
think you cared, I wouldn't bother pointing it out.
After reading all the replies and links I seem to fit all the proper
uses of singletons as described(mostl y), but I feel I didn't put that
information out very well.

I do have one question for Philip:To achieve the moral high-ground here, you might admit that most modules do
not write on your Singletons (do not set their Set() methods). Global
constants are harmless, therefor global defacto-constants inside Singletons
are mostly harmless.


Forgive me if I mis-understand, right now the opposite is true, evey
module does or can call "set" methods on the singleton(s).

reflecting on the comment on multithreading from dietmar and Philip's
comments have made me realize that I need to go back and refactor much
of the information I was keeping in the "program state" part of the
data format class structure. BTW this was already in my head because
no real design time was given, and I've really been the sole developer.
This just gave me the added push I need to get the cogs in my mind
moving properly.

I have some work ahead of me, but I'll be back with a better design and
more questions later.

Thank you all
JF


Hope none of my replies were too terse or sounded arguementative, its
been a long day at the end of an even longer week.

Feb 25 '06 #11
John Fly wrote:
Forgive me if I mis-understand, right now the opposite is true, evey
module does or can call "set" methods on the singleton(s).
Hmm. Suppose the Foo module Sets a 42 into a Singleton. Then the Bar module
reads it and uses the 42.

Now change the program. Maybe change Frob that calls Foo and Bob that calls
Bar. You don't notice that Bar now runs before Foo.

The program will fail in a mysterious way, at runtime.

If Bar called Foo directly to get the 42, then more kinds of changes to the
code will either work or fail at compile time.
reflecting on the comment on multithreading from dietmar and Philip's
comments have made me realize that I need to go back and refactor much
of the information I was keeping in the "program state" part of the
data format class structure. BTW this was already in my head because
no real design time was given, and I've really been the sole developer.
This just gave me the added push I need to get the cogs in my mind
moving properly.
Please don't say "refactor" without unit tests. That word is spreading a
little too far. I'm aware it appears in the test-free book Design Patterns,
but the book Refactoring has since taken care of that.
I have some work ahead of me, but I'll be back with a better design and
more questions later.


Please put them on news:comp.objec t . The people on this newsgroup who like
only raw sterile C++ syntax questions are getting antsy. And people using
other languages deserve to read these threads.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Feb 25 '06 #12

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

Similar topics

11
1691
by: Tito | last post by:
I have two questions about the singletons' chapter of Alexei Alexandrescu's "C++ Modern Design". 1. In the beginning of the chapter Alexei states that a "singleton" class implementation made of static member functions has the problem that the functions are not virtual, so that you have to touch the class' code in order to change the behaviour. But, how is a singleton meant to be inherited from? Is not the concrete class of the unique...
3
3160
by: Dominik Rau | last post by:
Hi. I've got the following problem here: In my application, I use a lot of Singletons, that are implemented as described in Gamma et al. (shortened): //.h class Singleton{ public: static Singleton* the(); private: static Singleton* _instance;
8
4450
by: 6tc1 | last post by:
Hi all, I'm having a problem where in my solution that contains multiple projects - I instantiate a singleton class in one assembly and then if another assembly tries to use that singleton class another instance of it is created. Basically: --Assembly 1 (the executable)-- -Main.cs-
6
1387
by: Steven Watanabe | last post by:
PEP 8 says, "Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators." I know that "is" is an identity operator, "==" and "!=" are the equality operators, but I'm not sure what other singletons are being referred to here. Also, I've seen code that does things like: if foo is 3: if foo is not '':
5
1496
by: Omega | last post by:
I'm interested in seeing a bit of discussion about using singletons in ASP.NET 2.0. Currently I've designed a singleton that gets a reference to it's single instance stored inside the ASP.NET application object. This is done to persist and make available live information across multiple sessions. I've read a little bit (almost nothing) about how singletons don't play nicely in clustered scenarios and would like to hear more on the
5
1468
by: Aykut Canturk | last post by:
Dear friends, I recently decided to move vb.net 2005 from vb6. my projects has average of 200 forms and 20 modules. I mostly write enterprise solution about production automation like applications. In VB6 it takes 15 to 20 second to open a project and almost less than 2 second to see the form after I click to project explorer. Compiling to EXE file takes rather long time, about 45 seconds to 1 minute. But in VB.net, to open a project...
6
10384
by: =?Utf-8?B?R29yZG8=?= | last post by:
Hello everyone, I've been trying for some time now to move to C++/CLI, but I have several large legacy C++ static libraries I need to use. When I set up a simple solution with a C++/CLI Winforms app and a C++ native static library, they work well together _unless_ I have, it seems, any static variables defined in any function in the native library. The libraries I'm trying to use all have Meyers Singletons in them, so they need to have...
7
1809
by: adam.timberlake | last post by:
I was reading an article on TalkPHP (http://www.talkphp.com/ showthread.php?t=1304) about singletons but I'm afraid I don't understand why I need to use them. I understand how to code them perfectly, it's just the theory I'm having some problems with. I did try searching on Wikipedia but it didn't yield any satisfactory reasoning, for me. Could someone explain it to me in basic terms, please. I initially came across singletons when I...
12
1429
by: Craig Allen | last post by:
Hey, forgive me for just diving in, but I have a question I was thinking of asking on another list but it really is a general question so let me ask it here. It's about how to approach making singletons. Background: I've been programming in python seriously for about a year now, maybe a little longer depending how you count, and the system I am making is sophisticated enough that I've had to enter into a few idioms which were beyond my...
0
9589
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
10048
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
9865
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
8872
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
7410
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
6674
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();...
1
3963
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
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.