是啊..我知道..我是一个simpleton ..所以什么是Singleton? [英] Yeah.. I know.. I'm a simpleton.. So what's a Singleton?

查看:84
本文介绍了是啊..我知道..我是一个simpleton ..所以什么是Singleton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过几次了解Singleton是什么。也许我只是太可视化了,所以任何人都可以简单的比喻来分解它。

I've tried a few times to understand what a Singleton is. Perhaps I'm just too visual.. so can anyone break it down in a simple analogy.

类似的帖子:

  • Different ways to initialize singletons
  • Singleton: How should it be used
  • Is this a good use of the Singleton pattern?
  • What is so bad about singletons?
  • Singleton: How should it be used
  • Singletons: good design or a crutch?
  • Global vs Singleton in .NET
  • On Design Patterns: When to use the Singleton?
  • Singleton with Arguments in Java
  • What is an efficient way to implement a singleton pattern in Java?
  • What's Alternative to Singleton
  • Most common examples of misuse of singleton class class
  • http://stackoverflow.com/questions/1395766/asp-net-objectdatasource-singleton
  • Using Singleton vs Single Call in .NET Remoting?
  • what is a singleton class? Can it help me running single instance of a class for two related services?

推荐答案

p>根据要求,以下是一些类比:

As requested, here are a few analogies:


  • 地球

  • 宇宙

  • 元素氧(有其他元素,但只有一个氧气,有很多氧分子,但只有一个规范的氧元素。)

  • True

  • False的概念

  • The Earth
  • The Universe
  • The element oxygen (there are other elements, but only one oxygen. There are lots of oxygen molecules, but only one canonical oxygen element.)
  • The concept of True
  • The concept of False

您可以实例化许多True对象,但它们都将引用相同的实际项目(即True的通用概念)。根据您的应用程序的域名,可能有更多具体的示例:

You could instantiate lots of True objects, but they will all refer to the same actual item (i.e. the universal concept of True). Depending on your application's domain, there may be more specific examples:


  • 数据库连接

  • 应用程序的主线程

  • 代表硬件设备的任何东西(即您只想实例化一个表示CPU0的对象)。

这篇关于是啊..我知道..我是一个simpleton ..所以什么是Singleton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆