上一页 1 ··· 4 5 6 7 8 9 下一页
摘要: 1.不使用系统内置方法操作字符串 >>> str = '程序员' >>> str1 = str[:1] +'(加)' + str[1:2] + '(班)' + str[2:] >>> str1 '程(加)序(班)员' 2.内置函数 capitalize() 转换首字母为大写 >>> str = 'p 阅读全文
posted @ 2020-08-01 14:25 coder_xds 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1.创建和访问元组 >>> temp = (1,2,3,4,5,6) >>> temp[1] 2 >>> temp[5:] (6,) >>> temp[2:] (3, 4, 5, 6) >>> temp2 = temp[1:] >>> temp2 (2, 3, 4, 5, 6) 元组的访问同列表一样 阅读全文
posted @ 2020-08-01 12:59 coder_xds 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 使用情景:系统通知用户,通知方式有站内信,邮件,手机短信3种方式,信的内容分普通,紧急两种程度,为了不避免两两组合,m* n种可能的搭配,使用桥接模式 // 抽象 abstract class Info{ protected $_send = null; // 发送器 (site, email, s 阅读全文
posted @ 2020-07-24 00:23 coder_xds 阅读(125) 评论(0) 推荐(0) 编辑
摘要: // 数据源类class Weather { public static function getWether() { $data = array( 'tep' => 28, 'wind' => 5, 'sun' => 'sunny' ); return serialize($data); } } 阅读全文
posted @ 2020-07-23 23:35 coder_xds 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 使用情景:假如一本书的上市,要经过创作,编辑加上摘要,SEO人员给书加上SEO关键词这么一个有序的过程,通过继承的方式的确可以做到有序地对文章装饰不同的东西,但是这样的纵深继承结构不太科学,所以从线上结构转换成一个父类多个子类的两层结构。 // 原始文章类 class Article { prote 阅读全文
posted @ 2020-07-23 23:14 coder_xds 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 使用情景:if,else判断太短,优化代码的可读性。 interface Math { public function calculate($a, $b); } class Calculator { private $_operation; public function __construct($ 阅读全文
posted @ 2020-07-23 22:06 coder_xds 阅读(129) 评论(0) 推荐(0) 编辑
摘要: /** * 观察对象 * Undocumented class */ class User implements SplSubject { public $loginCnt; private $observers; public function __construct() { $this->obs 阅读全文
posted @ 2020-07-22 23:28 coder_xds 阅读(153) 评论(0) 推荐(0) 编辑
摘要: class C { public function sayHello() { echo 'I am C'; } } class B { private $_c; public function __construct(C $c) { $this->_c = $c; } public function 阅读全文
posted @ 2020-07-22 22:14 coder_xds 阅读(176) 评论(0) 推荐(0) 编辑
摘要: <?php class A { private $_b; public function __construct($b) { $this->_b = $b; } public function sayHello() { $this->_b->sayHello(); echo 'I am A<br>' 阅读全文
posted @ 2020-07-21 23:21 coder_xds 阅读(194) 评论(0) 推荐(0) 编辑
摘要: <?php class A { private $_b; public function __construct($b) { $this->_b = $b; } public function sayHello() { $this->_b->sayHello(); echo 'I am A<br>' 阅读全文
posted @ 2020-07-21 22:55 coder_xds 阅读(179) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 下一页