使用“静态”用于实现Singleton模式的关键字 [英] using the "static" keyword to implement the Singleton pattern

查看:72
本文介绍了使用“静态”用于实现Singleton模式的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要打电话我会做类似的事情:


$ headline = McSelectJustOneField :: callDatastore(" cbHeadline");


是这正确使用了static关键字,来实现一个单独设计的



类McSelectJustOneField扩展了McSelect {

/ * *

* 11-21-03 - getter

* @param - $ infoToBeSought,在这种情况下,是该字段的名称

其内容是通缉的。

*返回混合(可以是字符串或整数或

字段中的任何内容)

函数static callDatastore($ infoToBeSought){

$ this-> setQueryObject(" GetJustOneField");

$ this-> setInfoToBeSought($ infoToBeSought);

$ this-> getInfo();

$ row = $ this-> getRowAsArrayWithStringIndex($ this-> dsResultPointer);

$ field = $ row [ 0];

返回$ field;

}


}

解决方案

headline = McSelectJustOneField :: callDatastore(" cbHeadline");


这是否正确使用static关键字来实现

Singleton设计?


级McSelectJustOneField扩展McSelect {

/ **

* 11-21-03 - getter

* @param -


infoToBeSought,在这种情况下,是需要内容的字段

的名称。

*返回混合(可以是字符串或整数或

字段中的任何内容)

函数static callDatastore(


infoToBeSought) {


To call I would do something like:

$headline = McSelectJustOneField::callDatastore("cbHeadline");

Is this the correct use of the static keyword, to implement a
Singleton design?

class McSelectJustOneField extends McSelect {
/**
* 11-21-03 - getter
* @param - $infoToBeSought, in this case, is the name of the field
whose contents are wanted.
* returns mixed (could be string or integer or whatever was in the
field)
function static callDatastore($infoToBeSought) {
$this->setQueryObject("GetJustOneField");
$this->setInfoToBeSought($infoToBeSought);
$this->getInfo();
$row = $this->getRowAsArrayWithStringIndex($this->dsResultPointer);
$field = $row[0];
return $field;
}

}

解决方案

headline = McSelectJustOneField::callDatastore("cbHeadline");

Is this the correct use of the static keyword, to implement a
Singleton design?

class McSelectJustOneField extends McSelect {
/**
* 11-21-03 - getter
* @param -


infoToBeSought, in this case, is the name of the field
whose contents are wanted.
* returns mixed (could be string or integer or whatever was in the
field)
function static callDatastore(


infoToBeSought) {


这篇关于使用“静态”用于实现Singleton模式的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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