473,322 Members | 1,379 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,322 software developers and data experts.

Singleton Object

Hi ,
Can anyone tell me when I can use singleton pattern. Will
it be good for implementing the dataaccess Layer. Will it
be usefull for the buisness object layer . Could you give
me a practicle example for using the singleton object.

Regards,
Srini
Nov 17 '05 #1
4 1385

"Srini" <rs*************@yahoo.com> wrote in message
news:0a****************************@phx.gbl...
Hi ,
Can anyone tell me when I can use singleton pattern. Will
it be good for implementing the dataaccess Layer. Will it
be usefull for the buisness object layer . Could you give
me a practicle example for using the singleton object.

Regards,
Srini


For dataaccess you probably want to use static methods, so NO instance.
A singleton could be used to hold configuration information that should not
change (much).

Hans Kesting
Nov 17 '05 #2
Singletons are most useful for Application settings, where you want the
object instantiated for the app and any changes in settings affect all
users.You could put your connection settings in a singleton, for example.

A data layer can be implemented as Static methods, ala the Microsoft Data
Access Application Block, but a Singleton is not a good idea unless everyone
is accessing the same exact data in the same exact manner, or you do not
mind if another person alters someone else's data access path. As this is
not a normal situation, this is not a good place for a singleton pattern.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Srini" <rs*************@yahoo.com> wrote in message
news:0a****************************@phx.gbl...
Hi ,
Can anyone tell me when I can use singleton pattern. Will
it be good for implementing the dataaccess Layer. Will it
be usefull for the buisness object layer . Could you give
me a practicle example for using the singleton object.

Regards,
Srini

Nov 17 '05 #3
Hello

I usually use Singletons when I want my singleton object to implement some
interface.
For example in the code below I can have a singleton object of datatype
IDbCustomerManager that can be either SQLCustomerManager or
AccessCustomerManager. This makes switching between Access and SQL easy. If
I don't need this feature I use static methods, fields and properties.

interface IDbCustomerManager{
void AddCustomer(Customer cust);
}

class SqlCustomerManager : IDbCustomerManager {
void AddCustomer(Customer cust) { // Add customer to a SQL server
database }
}
class AccessCustomerManager : IDbCustomerManager {
void AddCustomer(Customer cust) { // Add customer to an Access
database }
}

Best regards,
Sherif

"Srini" <rs*************@yahoo.com> wrote in message
news:0a****************************@phx.gbl...
Hi ,
Can anyone tell me when I can use singleton pattern. Will
it be good for implementing the dataaccess Layer. Will it
be usefull for the buisness object layer . Could you give
me a practicle example for using the singleton object.

Regards,
Srini

Nov 17 '05 #4
Sherif,

You are describing Interface inheritance, not an implementation of the
Singleton pattern.

See http://www.dofactory.com/Patterns/PatternSingleton.aspx for a
description and examples.

-Steve Jansen

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello

I usually use Singletons when I want my singleton object to implement some
interface.
For example in the code below I can have a singleton object of datatype
IDbCustomerManager that can be either SQLCustomerManager or
AccessCustomerManager. This makes switching between Access and SQL easy. If I don't need this feature I use static methods, fields and properties.

interface IDbCustomerManager{
void AddCustomer(Customer cust);
}

class SqlCustomerManager : IDbCustomerManager {
void AddCustomer(Customer cust) { // Add customer to a SQL server
database }
}
class AccessCustomerManager : IDbCustomerManager {
void AddCustomer(Customer cust) { // Add customer to an Access
database }
}

Best regards,
Sherif

"Srini" <rs*************@yahoo.com> wrote in message
news:0a****************************@phx.gbl...
Hi ,
Can anyone tell me when I can use singleton pattern. Will
it be good for implementing the dataaccess Layer. Will it
be usefull for the buisness object layer . Could you give
me a practicle example for using the singleton object.

Regards,
Srini


Nov 17 '05 #5

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

Similar topics

2
by: Rajarshi Guha | last post by:
Hi, I'm having a little problem with understanding the working of a singleton and borg class. Basically I nedd an class whose state will be shared across several modules. I found the stuff on the...
26
by: Uwe Mayer | last post by:
Hi, I've been looking into ways of creating singleton objects. With Python2.3 I usually used a module-level variable and a factory function to implement singleton objects. With Python2.4 I...
12
by: solex | last post by:
Hello, I am trying to model a session object that is essentially a collection of different items (connection string, user name, maps etc.) I would like this session object to be available to...
14
by: Paul Bromley | last post by:
Forgive my ignorance on this one as I am trying to use a Singleton class. I need to use this to have one instance of my Class running and I think I understand how to do this. My question however is...
2
by: Kevin Newman | last post by:
I have been playing around with a couple of ways to add inheritance to a JavaScript singleton pattern. As far as I'm aware, using an anonymous constructor to create a singleton does not allow any...
6
by: Manuel | last post by:
Consider the classic singleton (from Thinking in C++): ----------------------------------------------------- //: C10:SingletonPattern.cpp #include <iostream> using namespace std; class...
5
by: Rich | last post by:
The following code produced a singleton object with application scope when it should have had page scope: public class Singleton { private static Singleton uniqueInstance = null; private...
7
by: John A Grandy | last post by:
For a singleton class utilizes by ASP.NET 2.0 page processing: When initial instantiation is performed during the initial call to the retrieve instance method (let's call the method...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
0
by: George Sakkis | last post by:
On Jul 3, 6:58 pm, Urizev <uri...@gmail.comwrote: Because __init__() is called to initialize the state of an object *after* it has already been created. You should create a "new-style" class...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.