//SINGLETON - C#
using NUnit.Framework;
[TestFixture()]
public class SingletonTest
{
[Test()]
public void ObjectsAreTheSameTest()
{
DeploymentInfo firstDeployment = Singleton<DeploymentInfo>.UniqueInstance;
DeploymentInfo secondDeployment = Singleton<DeploymentInfo>.UniqueInstance;
Assert.AreSame(firstDeployment, secondDeployment);
}
}
//Singleton Pattern
//Generic Version
public class Singleton<T> where T : class, new()
{
private Singleton()
{
}
private class SingletonCreator
{
static SingletonCreator()
{
}
// Private object instantiated with private constructor
static internal readonly T instance = new T();
}
public static T UniqueInstance {
get { return SingletonCreator.instance; }
}
}
'SINGLETON - VB.NET
Imports NUnit.Framework
<TestFixture()> _
Public Class SingletonTest
<Test()> _
Public Sub ObjectsAreTheSameTest()
Dim firstDeployment As DeploymentInfo = Singleton(Of DeploymentInfo).UniqueInstance
Dim secondDeployment As DeploymentInfo = Singleton(Of DeploymentInfo).UniqueInstance
Assert.AreSame(firstDeployment, secondDeployment)
End Sub
End Class
'Singleton Pattern
'Generic Version
Public Class Singleton(Of T As {Class, New})
Private Sub New()
End Sub
Private Class SingletonCreator
Shared Sub New()
End Sub
' Private object instantiated with private constructor
Friend Shared ReadOnly instance As New T()
End Class
Public Shared ReadOnly Property UniqueInstance() As T
Get
Return SingletonCreator.instance
End Get
End Property
End Class
What an excellent interview. If you have chance listen to Kent speak rather then just reading the transcript of interview. The passion when he speaks about "programming" is amazing and impossible to show in transcript.
"...people are now asking the question: "How am I going to do agile
development?" and agile development isn't a thing you do, it's an
attitude, it's a set of personal values about responding to the real
world, being open to the information that is there and being willing to
do something about it.
That is agility. Yes, there is a lot of practices that come out of that
but to me that is where it starts, it's this attitude. If somebody
understood a bunch of practices and tried to do them, you could do
agile development without being agile and it's a disaster because
you're acting out of harmony with what you really believe when you do
that..." - Kent Beck
http://www.infoq.com/interviews/beck-implementation-patterns#