February 26, 2013

Singleton pattern

Singleton is using when you need a class that has only one instance, and you need to provide a global point of access to the instance. As you can notice, singleton is similar to the global variable. And as the global variable it can violates testability and scalability of your system. So you should use it carefully or not to use at all if you can. But if you need it, you can use this 'lazy' implementation. ('Lazy' means that the instantiation is not performed until an object asks for an instance, whereas global variables always consume resources when the application starts):
using System;

public class Singleton
{
   private static Singleton instance;

   private Singleton() {}

   public static Singleton Instance
   {
      get 
      {
         if (instance == null)
         {
            instance = new Singleton();
         }
         return instance;
      }
   }
}

February 24, 2013

Hello World!

Hello! My name is Alex. I've been working as a C# ASP.NET Developer for the last few years and to structure my knowledge I decided to write a blog. Also I will be glad if the information I will write here be useful for someone. As you can see at the top of the site I will be writing here mainly about C# and all that related to it. This is not my first experience of the writting a blog. But about such technical things on English I write at the first time. So if you see any mistake in my posts or English or just want to say something that can make this blog better, feel free to email me at info@alexzaitzev.pro or hit me on skype: alexzaitzev.

I want to start my blog from the post about Design Patterns. A bit later I will write about algorithms and some interesting tasks and hints in C#, but I think that Design Patters are one of the most important and useful thing, so let's start from them.
There are many articles about them, but when I need to find implementation some of them I had to visit many sites: no one has full and clear information about most of them. Not to mention their implementation. Thus next post I will devote to Singleton pattern. The easiest for understanding and using pattern.