Giter VIP home page Giter VIP logo

designpatterns's Introduction

设计模式

单例模式

单例模式的三个要素

  • 单例类构造函数的可见性为private
  • 提供一个类型为自身的静态私有成员变量
  • 提供一个共有的静态工厂方法

饿汉式单例类与懒汉式单例类的比较

  • 饿汉式单例类在类加载时就将自己实例化,它的优点在于无需考虑多个线程同时访问的问题,可以确保实例的唯一性;
  • 从调用速度和反应时间角度来讲,由于单例对象一开始就得以创建,因此要优于懒汉式单例;
  • 从资源利用率角度来讲饿汉式单例不及懒汉式单例;
  • 在系统加载时由于需要创建饿汉式单例对象,加载时间可能会比较长。

designpatterns's People

Contributors

yinyicao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.