.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Singleton Pattern and Abstract Class

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

I know what Singleton Pattern means and Abstract class means.

What I wanted to know was how would this apply to real world.

Could anyone give me any good example or simple explanation.

Say I have a simple website, why would I use any of the above if any.

Why would it simplify my architechture.

Thanks in advace. 

View Complete Post

More Related Resource Links

Singleton Design Pattern in C#, Vb.NET

Ensure a class has only one instance and provide a global point of access to it.

Singleton Design Pattern in Asp.net using C#

When we want to make a only one instance of a class and also making sure that there is a global access point to that object then the design pattern we user is called Singleton. The pattern ensures that the class is instantiated only once and that all requests are directed to that one and only object.

Abstract Factory Design Pattern (Sample in C# and VB .NET)

An abstract factory provides an interface for creating families of related objects without specifying their concrete classes. Sometimes one wants to construct an instance of one of a suite of classes, deciding between the classes at the time of instantiation. In order to avoid duplicating the decision making everywhere an instance is created, we need a mechanism for creating instances of related classes without necessarily knowing which will be instantiated.

Abstract Factory Pattern-Creational Patterns

The Factory pattern allowed us to decouple our client from an object which it uses. The Abstract Factory pattern extends this idea to manage separate families of objects.

A runtime selection, or configuration option, in our client could decide which family of objects is to be used. The Abstract Factory pattern allows us to write generic code to instantiate and use the family objects regardless of which family is chosen at runtime. The pattern also helps us enforce a rule where objects from just the chosen family are used uniformly by the client.

Singleton Pattern-Creational Patterns

The Singleton pattern is a specialist creational pattern as it's primary focus is to facilitate a single shared instance of our object rather than to decouple our client from the object's implementation as with the other creational patterns.

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

singleton class and multithreading


I have a singleton class thats used throughout an application.  The app will be multi threaded, each thread will access methods in the singleton class.  Is it best to create an instance of the singleton class at application startup then pass that into each thread, or is it safe to create an instance in each thread separately ?  (I check that no instance currently exists in the singleton class itself, so only 1 instance will ever be invoked)

Abstract class properties work when not implemented?

Hi, I was just looking at a code example and was confused by the behavior of classes implementing an abstract class. So the project has an abstract class named GeneralItem with some abstract properties. Another class named NspItem inherits GeneralItem. NspItem does not implement any of the abstract properties from GeneralItem yet I can write code that successfully sets those properties. How is that working? Is the compiler automatically creating them for me? Example: public abstract class GeneralItem { public string Description { get; set; } } public class NspItem : GeneralItem { public NspItem() { } } static class Program { [STAThread] static void Main() { NspItem item = new NspItem(); item.Description = "Some String"; Console.WriteLine(item.Description); } } //Output would be: Some String

when abstract class and when interface

hi...need a practical scenario where interface can be used and where abstract class and also the need for constructors and destructors practically?? theoritically i know the differences ..but during coming to the implementation how to decide??...like why do u declare a class as abstract... thanks in advance 

Singleton Pattern


earlier today i was readind about singleton pattern

now i m trying to implement in a testing project

which is like -

public class prodcuttable
    private static prodcuttable _instance = new prodcuttable();
    public static prodcuttable Instance()
        return _instance;

    private prodcuttable()

    public DataTable loadtable()
        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn();
        dc.ColumnName = "ID";
        dc.DataType = Type.GetType("System.Int32");

        dc.ColumnName = "Name";
        dc.DataType = Type.GetType("System.String");
        DataRow dr = dt.NewRow();
        dr["ID"] = 1;
        dr["Name"] = "Aftab";

        return dt;
        //throw new NotImplementedException();

but when i m trying to implement in my Default page

binding with gridview

if (!IsPostBack)
            GridView1.DataSource = prodcuttable.Instance();

its giving me error

The type initializer for 'prodcuttable

Use UserControl, where the base class is an abstract one.




When I inherits my usercontrol from an abstract class, I got the warning message on design time.

How can I overcome this warning message?

The designer must create an instance of type but it cannot because the type XYZ is declared as abstract.


Thanks :)

"Singleton" pattern in WF 4.0


I am trying to do a singleton pattern with WF and AppFabric. I  want just one instance of a workflow running in the cluster.

I have tried a biztalk style: a method (CallService()) that creates the instance, and the same method in other receive activity (CallService()) that do not have the cancreateinstance checked. (I think I could correlate it through the xpath to the action in the soap message, but lets forget about correlating at this step).

My problem is that WF always creates the instance and does not correlate in the second call.

Do you know how to solve it? I would like to priorize the correlation against the creation of the instances. Any other way to do it?

Thanks in advance.

Implementing the Singleton Pattern in C#

The singleton pattern is one of the best-known patterns in software engineering. Essentially, a singleton is a class which only allows a single instance of itself to be created, and usually gives simple access to that instance. Most commonly, singletons don't allow any parameters to be specified when creating the instance - as otherwise a second request for an instance but with a different parameter could be problematic! (If the same instance should be accessed for all requests with the same parameter, the factory pattern is more appropriate.) This article deals only with the situation where no parameters are required. Typically a requirement of singletons is that they are created lazily - i.e. that the instance isn't created until it is first needed.

Abstract Class


what is the function of abstract class, why design pattern need to build BLL and DAL

anyone give an example for my reference as I am getting strat to build my web-based  project 

Question About singleton class


Just wanted to know if a singleton class could be inherited and derived.


Abstract class


In my engineering i never understand abstract class

but now after enter in developing field i go through various kind of RND work

Please solve my problem about abstract  class 

My code below

in my connection class i declare one more class name is shape


public abstract class Shape
    public abstract void Test(int x, int y)
public abstract class Shape1 : Shape
public class Shape2 : Shape1
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend