classXmlParamHandlerextendsParamHandler { publicfunctionwrite(): bool { // write XML // using $this->params } publicfunctionread(): bool { // read XML // and populate $this->params } } // listing 06.06 classTextParamHandlerextendsParamHandler { publicfunctionwrite(): bool { // write text // using $this->params } publicfunctionread(): bool { // read text // and populate $this->params } }
$test = ParamHandler::getInstance(__DIR__ . "/params.xml"); $test->addParam("key1", "val1"); $test->addParam("key2", "val2"); $test->addParam("key3", "val3"); $test->write(); // writing in XML format
$test = ParamHandler::getInstance(__DIR__ . "/params.txt"); $test->read(); // reading in text format $params = $test->getAllParams(); print_r($params);
# UML
通常要靠程式碼來描繪出整個架構會比較不好表示, 所以可以通過 UML 來描繪整個架構
# Class
# Abstract Class
# Interface
# Class Properties & Methods
# Inheritance
Cd product 以及 BookProduct class 繼承了 ShopProduct
# Implementation
ShopProduct 實作了 Chargeable interface
# Relations
Teacher class 與 Pupil class 之間有 relationship, 可能是 Teacher 有 Pupil, 也可能是 Pupil 有 Teacher, 也可能互相有
Teacher class 有一個或多個 Pupil class
Teacher class 與 Pupil class 互有一個或多個
一個 Teacher class 有多個 Pupil class
一個 Teacher class 有 5~10 個 Pupil class
# Aggregation
SchoolClass class 由 Pupil class 組成, 但刪除 A SchoolClass 時不見得要刪除對應的 Pupil class, 因為 Pupil class 可能被複數的 SchoolClass 所擁有
# Composition
person 由對應的 SocialSecurityData 組成, 每個 SocialSecurityData 只屬於特定的一個 person, 若刪除 person 則必定要刪除 SocialSecurityData
留言