We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
此笔记摘抄于《Android源码设计模式解析与实战》一书
确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。
确保一个类有且只有一个对象的场景,避免了产生多个对象消耗过多的资源,或者某种类型的对象只应该有且只有一个。例如,创建一个对象需要消耗的资源过多,如要访问IO和数据库等资源,这时候就要考虑使用单例模式。
private static Singleton singleton = new Singleton(); //构造函数私有 private Singleton(){} //公有的静态函数,对外暴露获取单例对象的接口 public static Singleton getInstance(){ return singleton; } }
The text was updated successfully, but these errors were encountered:
panyz
No branches or pull requests
前言
单例模式的定义
单例模式的使用场景
确保一个类有且只有一个对象的场景,避免了产生多个对象消耗过多的资源,或者某种类型的对象只应该有且只有一个。例如,创建一个对象需要消耗的资源过多,如要访问IO和数据库等资源,这时候就要考虑使用单例模式。
单例模式的实现
单例模式的简单示例
The text was updated successfully, but these errors were encountered: