---
title: "Discussion on \"设计模式（三）——创建型：单例模式-数据管理哲学\" | Hashnode"
description: "Discussion on \"设计模式（三）——创建型：单例模式-数据管理哲学\". 单例模式的实现思路\n单例模式就是保证一个类仅有一个实例，并提供一个访问它的全局访问点。\n一般情况下，当我们创建了一个类后，可以通过new关键字调用构造函数进而生成任意多的实例对象。那我们该如何保证一个类仅有一个实例？其实要做到这一点，就需要构造函数具备判断自己能否已经创建过一个实例的能力。\nclass SingleDog {\n  static instance: SingleDog;\n\n  show() {\n    console.log(\"我是一个单例对象\");\n  }\n\n  static g..."
url: "https://hashnode.com/posts/6k66k6h5qih5byp77yi5lij77yj4ocu4ocu5yib5bu65z6l77ya5y2v5l6l5qih5bypleavsoanrueuoeeqhuwtsuwtpg/63292dd099624fc71cd52f73"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [设计模式（三）——创建型：单例模式-数据管理哲学](https://yesx.hashnode.dev/6k66k6h5qih5byp77yi5lij77yj4ocu4ocu5yib5bu65z6l77ya5y2v5l6l5qih5bypleavsoanrueuoeeqhuwtsuwtpg?utm_source=hashnode&utm_medium=feed)

单例模式的实现思路 单例模式就是保证一个类仅有一个实例，并提供一个访问它的全局访问点。 一般情况下，当我们创建了一个类后，可以通过new关键字调用构造函数进而生成任意多的实例对象。那我们该如何保证一个类仅有一个实例？其实要做到这一点，就需要构造函数具备判断自己能否已经创建过一个实例的能力。 class SingleDog { static instance: SingleDog; show() { console.log("我是一个单例对象"); } static g...

Sep 20, 2022 · 2 min read · yesx.hashnode.dev  
Read the article

-   [#6k66k6h5qih5byp](https://hashnode.com/tag/6k66k6h5qih5byp)

## Written by

[Yesx](https://hashnode.com/@hewuhu)

@hewuhu · china

  
[View profile](https://hashnode.com/@hewuhu)

RECORD SHARE GROWTH

新时代农民工一枚

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
