例如
public class DiskUtil {
private DiskUtil() { }
public static FUNC(){}
}
这样的类,往往提供一些静态的函数来生成该类的实例,只要这个类有公开的属性、方法,得到实例引用的一方还是可以调用的,一个例子是singleton。
外面调用只能调用DiskUtil 的静态函数Func,而不能A a =...
分类:
其他好文 时间:
2014-08-22 12:58:48
阅读次数:
243
随机输出保平安
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N = 100005;
int a[N];
int main() {
int T, cas = 0;
scanf("%d", &T);
while(T-...
分类:
其他好文 时间:
2014-08-21 19:27:34
阅读次数:
171
随机输出保平安啊
和hdu4888一个意思,先跑个网络流然后dp判可行。
==n^3的dp过不了,所以把n改成200。
==因为出题人没有把多解的情况放在200*200以外的矩阵。
#include
#include
#include
#include
#include
using namespace std;
const int MAX_N = 1207;
const in...
分类:
其他好文 时间:
2014-08-21 19:26:44
阅读次数:
226
我们先来看一个例子:var Demo1 = function(val){ this.value = val; this.getValue = function(){ return this.value; } };var demo1Obj = ...
分类:
Web程序 时间:
2014-08-21 16:38:35
阅读次数:
1111
看到评论中有关于体制和国内复杂人际关系的讨论,这个问题太宏大了,三天三夜也聊不完,而且背景不同,经历不同,想法肯定不同。我还是只讲故事,不做评论。是一个朋友的事,我和他本来不熟,因为同一天在长春考托福,碰巧在火车上遇到。一上车,他就把手机关了机,我问他,为什么不给家里报个平安?他说,父母不知道他.....
分类:
其他好文 时间:
2014-08-20 20:51:22
阅读次数:
150
Php面向对象 – 单例模式
保证类只有一个实例
1. 如何可以解决一个类可以被无限地实例化?
New,就能实例化一次,怎么去限制,用户不能无限次地new?
将构造方法私有化。所有外部的new都操作失败
class MySQLDB
{
private function __construct()
{
}
...
分类:
Web程序 时间:
2014-08-20 00:02:35
阅读次数:
335
今天准备学习singleton pattern,顾单词思含义,就是一个实例的意思。单例的实现思路是:私有化构造函数,提供公有方法获取类的实例。下面定义一个音乐播放器类MusicPlayer,观察单例的实现方法class MusicPlayer{ private static readonly ...
分类:
其他好文 时间:
2014-08-16 13:42:00
阅读次数:
219
解决的问题:保证内存中只有一个对像(比如多个程序使用同一个配置信息);如 何 实现:1、不允许其它程序用new 创建该类对象 2、在该类创建一个本类实例 3、对外提值一个方法让其它程序获取该对象步骤: 1、私有化该类构造函数; 2、通过new在本类中创建一个静态本...
分类:
其他好文 时间:
2014-08-13 18:05:27
阅读次数:
214
模拟大法保平安_(:зゝ∠)_
#include
#include
#include
#include
using namespace std;
const int N = 1;
struct node{
int x, y, val;
node(int a=0,int b=0,int c=0):x(a),y(b),val(c){}
bool operator<(...
分类:
其他好文 时间:
2014-08-12 19:07:44
阅读次数:
224
有了解过spring框架的童鞋们就知道,spring的bean默认是什么形式呀?———单例形式的。
问:那什么叫做单例?单例其实就是Singleton,顾名思义就是只有单个的实例对象操作。
那为什么要使用单例呢?
至于这个问题,后面再做解释,我们先看代码:
package me.javen.oop;
public class SingletonDemo {
public static...
分类:
编程语言 时间:
2014-08-12 17:24:44
阅读次数:
231