Posts Tagged ‘Patterns’

2. Software Architecture – Key Principles

August 17, 2011 Leave a comment

Common Application Architecture

Read more…


1. Software Architecture – What is Software Architecture?


I have wanted to do something like this for a long time. There is so much out there on what software architecture is and what the right way is to implement “good architecture”.  So i will attempt to extract what i think are the important points from select articles and discussions out there today. Here goes…

Software application architecture is the process of defining a structured solution that meets all of the  technical and operational requirements, while optimizing common quality attributes such as performance, security, and manageability. It involves a series of decisions based on a wide range of factors, and each of these decisions can have considerable impact on the quality, performance, maintainability, and overall success of the application.

Read more…

Singleton Pattern Implementation in C#

February 6, 2011 Leave a comment

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.

There are various different ways of implementing the singleton pattern in C#. I shall present them here in reverse order of elegance, starting with the most commonly seen, which is not thread-safe, and working up to a fully lazily-loaded, thread-safe, simple and highly performant version.

This implementation has four common characteristics:

1. A single constructor, which is private and parameterless. This prevents other classes from instantiating it (which would be a violation of the pattern). Note that it also prevents subclassing – if a singleton can be subclassed once, it can be subclassed twice, and if each of those subclasses can create an instance, the pattern is violated. The factory pattern can be used if you need a single instance of a base type, but the exact type isn’t known until runtime.
2. The class is sealed. This is unnecessary, strictly speaking, due to the above point, but may help the JIT to optimise things more.
3. A static variable which holds a reference to the single created instance, if any.
4. A public static means of getting the reference to the single created instance, creating one if necessary.

Note that in the two implementation below we use a public static property Instance as the means of accessing the instance. The property could easily be converted to a method, with no impact on thread-safety or performance.


Read more…

Categories: Architecture Tags: ,
%d bloggers like this: