美文网首页
单例设计的几种写法

单例设计的几种写法

作者: 我的_一个道姑朋友 | 来源:发表于2017-04-03 15:11 被阅读0次

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 泛型

{

class Program

{

static void Main(string[] args)

{

aaa.a();

}

}

public class aaa

{

public static void a()

{

Brid brid = Brid.brid();

Console.WriteLine(brid.i);

int a=plane.Instance.j;

Console.WriteLine(a);

//int b = BT.bt.a;

//Console.WriteLine(b);

int c=  TapEvent.inst.c;

Console.WriteLine(c);

Console.ReadKey();

}

}

class plane//单例

{

public int j = 20;

private static plane mInstance;

public static plane Instance

{

get

{

if (null == mInstance) mInstance = new plane();

return mInstance;

}

}

public void StartGame()

{

Console.WriteLine("plane单例被调用了!");

}

}

public  class Brid//单例

{

public int i = 10;

private static Brid mBrid = null;

public static Brid brid()

{

if (mBrid == null) mBrid = new Brid();

return mBrid;

}

public void StartGame()

{

Console.WriteLine("brid单例被调用了!");

Console.ReadKey();

}

}

class BT//单例

{

public int a = 30;

private static BT mbt;

public static BT bt

{

get { return mbt; }

set { mbt = value; }

}

void start()

{

mbt = this;

}

}

class TapEvent//单例

{

public int c = 40;

private static TapEvent _Inst;

public static TapEvent inst { get { return _Inst; } }

}

}

相关文章

  • 单例模式

    单例设计模式是几种设计模式中比较容易理解的,手写单例模式也是面试频繁问到的。下面总结一下单例模式的几种写法: //...

  • Java设计模式—单例模式

    概念 java中单例模式是一种常见的设计模式,单例模式的写法有好几种,比较常见的有:懒汉式单例、饿汉式单例。单例模...

  • java 24 设计模式

    单例模式java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例、饿汉式单例、...

  • 单例设计的几种写法

    using System; using System.Collections.Generic; using Sys...

  • java设计模式(一)

    概念: java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例、饿汉式单例、...

  • Java设计模式之单例模式(几种写法及比较)

    概念: Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例、饿汉式单例、...

  • 单例模式

    概念:Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例、饿汉式单例、登...

  • JAVA设计模式之单例模式

    概念 java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例、饿汉式单例、登...

  • Java设计模式_单例模式

    概念 java中单例模式是一种常见的设计模式,单例模式的写法有好几种.这里主要介绍:懒汉式 饿汉式. 单例模式有...

  • java设计模式之单例模式

    概念: Java中的单例模式是一种常见的设计模式,单例模式的写法有好几种,主要有以下三种:懒汉单例,饿汉式单例,登...

网友评论

      本文标题:单例设计的几种写法

      本文链接:https://www.haomeiwen.com/subject/eqqoottx.html