Simple screenshot that explains the singleton invocation.
Here is the code:
/*
Some class,such as a config file,need to be only one.So we need to control the instance.
1,private the constructor and create only one instance in the class itself.
2,provide a method for the others to get the 'only one' instance.
*/
package kju.obj; import static kju.print.Printer.*;
public class SingletonDemo {
public static void main(String[] args) {
SingleConfig con01 = SingleConfig.getInstance();
SingleConfig con02 = SingleConfig.getInstance();
println("con01 color : " + con01.getColor());
println("con02 set color : ");
con02.setColor("Blue");
println("con01 color : " + con01.getColor());
/*
con01 color : Orange
con02 set color :
con01 color : Blue
*/
}
} class SingleConfig {
private String color = "Orange";
private static SingleConfig s = new SingleConfig(); private SingleConfig() {}
public static SingleConfig getInstance() {
return s;
} public void setColor(String color) {
this.color = color;
} public String getColor() {
return color;
}
}
And the corresponds the code above:
Simple screenshot that explains the singleton invocation.的更多相关文章
- Simple screenshot that explains the non-static invocation.
Here is the code: /* Instance invocation in the memory: */ package kju.obj; import static kju.print. ...
- recursive - simple screenshot but detail principle.
the code below demonstates the principle of the'recursive-call' that the programing beginner may be ...
- Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#
原文链接地址: http://csharpindepth.com/Articles/General/Singleton.aspx#unsafe Implementing the Singleton P ...
- c# 几种singleton 实现
http://csharpindepth.com/Articles/General/Singleton.aspx#introduction 4th在线看 https://www.manning.com ...
- Implementing the Singleton Pattern in C#
Table of contents (for linking purposes...) Introduction Non-thread-safe version Simple thread safet ...
- Burp Suite教程(英文版)
In this article, we are going to see another powerful framework that is used widely in pen-testing. ...
- Multithreading annd Grand Central Dispatch on ios for Beginners Tutorial-多线程和GCD的入门教程
原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written a ...
- [学习笔记]设计模式之Facade
写在前面 为方便读者,本文已添加至索引: 设计模式 学习笔记索引 Facade(外观)模式定义了一个高层接口,它能为子系统中的一组接口提供一个一致的界面,从而使得这一子系统更加容易使用.欢迎回到时の魔 ...
- 《PHP 设计模式》翻译完毕
翻译进度请见:https://laravel-china.org/docs/php-design-patterns/2018?mode=sections 设计模式不仅代表着更快开发健壮软件的有用方法, ...
随机推荐
- h.264并行解码算法2D-Wave实现(基于多核共享内存系统)
cache-coherent shared-memory system 我们最平常使用的很多x86.arm芯片都属于多核共享内存系统,这种系统表现为多个核心能直接对同一内存进行读写访问.尽管内存的存取 ...
- 在eclipse中安装activiti插件
最近在学习activiti,先学习安装插件吧. 单击help->Install new Software 然后添加资源 name:activiti location:http://activit ...
- WordPress Event Easy Calendar插件多个跨站请求伪造漏洞
漏洞名称: WordPress Event Easy Calendar插件多个跨站请求伪造漏洞 CNNVD编号: CNNVD-201309-083 发布时间: 2013-09-11 更新时间: 201 ...
- Linux Kernel 多个本地拒绝服务漏洞
漏洞名称: Linux Kernel 多个本地拒绝服务漏洞 CNNVD编号: CNNVD-201308-154 发布时间: 2013-08-12 更新时间: 2013-08-12 危害等级: 漏 ...
- 使用sqlhelper的简单增删改查
一:所说的简单的三层构架,就是说没有业务逻辑层,将各层没有放到单独的项目中,解决方案如下: 二:form1.cs的详细代码 using System; using System.Collections ...
- HDOJ 1081(ZOJ 1074) To The Max(动态规划)
Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle ...
- (转)java多线程的一篇好文
云转型基石ThinkServer特性解析 2013-05-29 10:47 佚名 importnew 字号:T | T 本文只是一些针对初学者或者新手的问题,如果你已经具备良好的基础,那么你可以跳过本 ...
- mysql使用mysqldump导出数据出错
mysqldump -hlocalhost -uroot -p123456 student_info jssypk > c:/databackup.sql 导出表结构 mysqldump - ...
- SQL 按月统计(两种方式) 分类: SQL Server 2014-08-04 15:36 154人阅读 评论(0) 收藏
(1)Convert 函数 select Convert ( VARCHAR(7),ComeDate,120) as Date ,Count(In_code) as 单数,Sum(SumTrueNum ...
- shell 验证ip
#!/bin/bash function isIp(){ IP=$ ];then echo "Wrong IP!" exit else a=`echo $IP | awk -F . ...