Example Language:c#
Regarding technical s: OOP, SingleInstance Model
======================BaseClass===========================================
public class SingleInstance<T> where T:class,new ()
{
private static T me;
public static T GetIns()
{
if (me == null)
{
me = new T();
}
return me;
}
public void OutPut()
{
Console.WriteLine("Single Demo");
}
}
======================Demo Class===========================================
class SingleDemo:SingleInstance<SingleDemo>
{
}
=======================Main Class============================================
}
}
Output:SingleDemo
Regarding technical s: OOP, SingleInstance Model
======================BaseClass===========================================
public class SingleInstance<T> where T:class,new ()
{
private static T me;
public static T GetIns()
{
if (me == null)
{
me = new T();
}
return me;
}
public void OutPut()
{
Console.WriteLine("Single Demo");
}
}
======================Demo Class===========================================
class SingleDemo:SingleInstance<SingleDemo>
{
}
=======================Main Class============================================
static void Main(string[] args)
{
{
SingleDemo.GetIns().OutPut();}
}
Output:SingleDemo