Skip to main content

Singleton-Design patterns- step by step explanation with simple examples for beginners to intermediate

Singleton-Design patterns - Software Design patterns - Design patterns in C#.NET - easy simple example

what is Singleton design pattern
In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system. The term comes from the mathematical concept of a singleton.

using System;

namespace SingleTonnDesignPatternExample
{
    class Logger
    {
        private static Logger logger;
        private Logger()
        {

        }

        public static Logger GetInstance()
        {
            if (logger == null)
            {
                logger = new Logger();
            }
            return logger;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Logger logg = Logger.GetInstance();
        }
    }

}



Comments

Popular posts from this blog

Asp.net grid CRUD with ADO.NET

Asp.net grid CRUD with ADO.NET A GridView is a graphical control element that presents a tabular view of data. A typical Grid View also supports some or all of the following: Clicking a column header to change the sort order of the Grid. Dragging column headers to change their size and their order. The GridView control displays the values of a data source in a table. Each column represents a field, while each row represents a record. Support to data source controls, such as SqlDataSource. Support sort capabilities. Support update and delete capabilities. Support paging capabilities. Support row selection capabilities. Code behind feature access to the GridView object model to dynamically set properties, handle events, and so on. Many key fields. Many data fields for the hyperlink columns. Customized style layout through themes and styles using css and javascript. The following operations can be performed using GridView control in ASP.NET using C# code behind. Fea

MVC Action Filters using log4net

Add log4net dll reference to your MVC project ------------------------------------------------------------------------------ Create following  model inside your models folder ------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace MVCWebApp.Models {     public class LoggingFilterAttribute : ActionFilterAttribute     {         #region Logging         /// <summary>         /// Access to the log4Net logging object         /// </summary>         protected static readonly log4net.ILog log =           log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);         private const string StopwatchKey = "DebugLoggingStopWatch";         #endregion         public override void OnActionExecuting(ActionExecutingContext filterContext)

Cascading Dropdown in Angular 7

Cascading Dropdown in Angular 7 And Web API Prerequisite Angular 7  Web API HTML/Bootstrap SQL Server Cascading DropDownList means a series of dependent DropDownLists where one DropDownList is dependent on another DropDownList. Child DropDownLists are populated based on the item selected in dropdownlist by a user. For example, loading all states in a country. There are three parts of this article. Create a SQL Server database with two tables, parent and child.  Create a Web API using ASP.NET Web API Project template Create an Angular 7  app Part 1. Create a Database For this article, I have created a database and two tables. If you already have data representing a parent-children form, you may skip this step. Step 1.  Open SQL Server Management Studio, connect to a server, and get ready to execute SQL.  Step 2. Create a database using the following query. create   Database  CaseCaddingDDL   Step 3.  Create a table, CountryMaster, usin