June 30, 2012

Singleton pattern

I'm sorry for pause in writing new posts about design patterns.  
Unfortunately, I had no free time, but now I'm really ready to do it.

So, today I'm going to write a post about the most popular and well-known design pattern - Singleton.

The essence of Singleton is to provide :
  • exactly one instance of class across the system;
  • simple access to it.
The implementation of Singleton based on creation a class with a method(or property in .NET) that creates an instance of this class if one doesn't exists yet. The constructor of class must be private to prevent other ways of initialization. Also Singleton must be carefully used in multi-threaded applications because in one point of time, the two threads may create two different instances (which violates singleton pattern).

Below I'll explore the most frequent implementations of pattern. As always, I'll show structural code and real-world code.

June 15, 2012

.NET Parameter passing


Recently, I had a dispute with co-worker about .NET passing parameter. So, I decide to write post about it and clarify some aspects. This post will show you how parameter passing is handled in memory.
Also this post expects that readers knew what's the difference between a value-type and a reference-type in .NET. By the way, I'm going to dive deeper into this question. Thus, wait for another post :)

In .NET we may passing parameter by value or by reference.
I break out a post into four parts :
  • Passing value-type variables by value;
  • Passing value-type variables by reference;
  • Passing reference-type by value;
  • Passing reference-type by reference.

June 9, 2012

Facade pattern


First pattern which I'll try to explore is a structural pattern - Facade.

Before we go to the pattern I think we must understand a concept of subsystem.

Subsystem is a part of large system that consists of a set of elements and relations.
Let's look for simple example for better understanding.


Here you can see a system which consists of four subsystems : UserInterface, OrderManagement, SeatingManagement and Database. Each subsystem has own logic as well as relations to another subsystem(s).

June 7, 2012

Structure of design patterns


From wikipedia :
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.

I always wanted to write all well-known design patterns into one repository with details and own examples. I think that my blog and github (all sources will be avaible on github) is comfortable for it.
So, every Saturday I'll be write a post about exactly one design pattern.

In this post, I want to group the design patterns into the categories.
Historically, design patterns were grouped into : creational patterns, structural patterns, and behavioral patterns.

From each group I chose only most popular and well-known patterns.

June 6, 2012

How To Solve “Not Enough Time”

It's would be a very small post.

I just wanna to share with you really cool article about pessimistic statement - “Not Enough Time”.

Have a nice day !

June 4, 2012

Learning SQL by Alan Beaulieu

Yesterday, I finished reading my first book about SQL - Learning SQL by Alan Beaulieu.

Should say that a book has well structured chapters. In first chapter, author exposes background and explains what is  SQL. The next several chapters shows you how to write simple SQL statements and issues their via mysql command-line tool (author uses MySQL database server for examples).

I found for myself very interesting chapters about transactions, indexes and constraints. Before I've never read anything about these concepts.


Book is suitable for newcomer. After reading this book you will have strong understanding about main concepts of relational database. Also you'll be write clear, high perfomance queries.

It's 7/10

June 3, 2012

What is deadlock?

First, what is transaction?

Transaction is a device for grouping together multiple SQL statements such that either all or none of the statements succeed (a property known as atomicity).

Database servers use locks for simultaneous access to data resources. When some portion of the database is locked, any other users wishing to modify (or possibly read) that data must wait until the lock has been released. There are several locking strategies, but this post doesn't cover it. There are also a number of different strategies that you may employ when deciding how to lock a resource (table, page or row locks).
In the next example, I'll assume that database server employs table lock. So, what is deadlock?

April 10, 2012

Haskell. First steps.

Today I gonna touch very important thing in Haskell - high-order functions and types.
Actually, I split this topic in several posts. Thereby, welcome to the first part of those series.