2012年11月23日 星期五

POSD學習筆記(3)-coupling&cohesion

coupling(耦合度):表某一class對另一class的依賴程度
ex:
A吃、喝、拉、撒都要靠B才能動作,則稱A對B擁有高coupling
反之A若可以獨力完成所有工作,則擁有低coupling

cohesion(聚合度):表某一class做的工作種類
ex: 
class A包含了「走路」、「攻擊」、「說話」...etc,則我們說A擁有高cohesion
反之若A只做「走路」一件事情,則稱A擁有低cohesion



coupling: means the level of one class depends on another.
ex: 
if A needs B to do things such like "eat", "drink", ...etc,  then we say that A has high coupling to B.
otherwise if A can done everything by itself, then A has low coupling.

cohesion: means the number of different work that a class can do.
ex:
 if A can do like "walk", "attack", "talk", ...etc, then we say that A has high cohesion.
otherwise if A do only "walk" one thing, we say it has low cohesion.

2012年10月14日 星期日

POSD學習筆記(2)-UML與coding

Dependency (uses a)  X-->Y
Ex:X uses Y,X call Y的funtion。

Association (knows a)  X→Y
Ex:X knows Y,X new了Y,且可使用Y的變數及funtion。

Composition (has a)  X◆→Y
Ex:X has a Y,X有Y做為他的變數。

Inheritance (is a)  X△→Y
Ex:Y is a X,Y繼承了X。

Implementation (can do)  X△-->Y
Ex:Y can do X,Y可以做X可以做的事情,可是Y不是X。

2012年10月5日 星期五

C++學習筆記(2)-雙冒號的使用

:: 雙冒號可以使用在...

1.定義某一class內method的實作
    ex1:
    class ex{
      public:
        int testValue;
        int test1(int a);
    };

    int ex::test1(int a){
       return a;
    }

2.也可以用來讀取class內的變數值
    ex2:
    承ex1...
    int ex::test1(int a){
      return a + ::testValue;
    }

C++學習筆記(1)-class與struct的差別

 引用:
   根據C++ standard的描述, class 和 struct 對於 class definition 的差別在於:
   1. 對於 member 的 default access level 不同(std.11)
   2. 對於 base class 的default access level 不同(std.11.2)

整理:
1. class預設權限為private,struct預設權限為public
2. 兩者在C++可以互相繼承
3. C++原本叫做C with Class,可以看出Class為C++的核心理念
4. 兩者幾乎無異,可以只使用其一
5. 若要 class 或 struct 能做 expilcit inialization,該 class 不能有 constructor,不能有 private or protected data member,不能有 base calss,以及不能有 virtual function




expilcit inialization(initializing array):以array的方式做initial
ex:class A{
         int a;
         string b;
         double c;
     }
     
     A test = {1, "a", 1.0};//initialize A 裡面的變數

2012年9月26日 星期三

POSD學習筆記(1)-UML

1. Know:A可能有call到B這個funtion,但是B如何並不會影響到A的結果。
                相反的,B並不知道A的存在。

2. Use:A有使用到B,且B改變時,A改變。但是A改變時,B不變。此為單向關係。

3. Has:假設A為硬碟,B為資料,則當A爆炸時,B也不復存在。

4. Has:假設A為公司,B為員工,但是當公司倒閉時,員工仍然健在。
(↑這項不實用且不常使用)

5. Is:假設A為人類、B為台灣人、C為日本人、D為美國人,
         「台灣人」、「日本人」、「美國人」都繼承於「人類」這一類別,
          則B、C、D都繼承於A。

2012年9月1日 星期六

PHP學習筆記(1)-變數與字串

字串的表示可以用" "或' ',不同處在於在" "中若出現已宣告的變數,會將其代號轉換成變數內容,而' '則不會。
(You can use also " " or ' ' to present a string, the difference is that if there are any variables in the string with " ", the output will be the content of the variable, although ' ' will only print the name of it.)

Ex:
   $test1 = "hi";
   $op1 = "$test1 ,I am handsome <br/>";
   $op2 = '$test1 ,I am handsome';

   echo $op1;
   echo $op2;

   輸出(output):
   hi ,I am handsome
   $test1 ,I am handsome

也可以用 . 來連接變數及字串。
(You may use . to combine variable and string, too.)

Ex:
   $test1 = "hi";
   $op1 = $test1 . " ,I am handsome <br/>";
   $op2 = $test1 . ' ,I am somehand';

   echo $op1;
   echo $op2;

   輸出(output):
   hi ,I am handsome
   hi ,I am somehand