當前位置:編程學習大全網 - 源碼下載 - Php購物車checkout:下面怎麽寫check out()方法,最好解釋壹下,然後最好在下面的伊卡特類中解釋壹下check()方法。

Php購物車checkout:下面怎麽寫check out()方法,最好解釋壹下,然後最好在下面的伊卡特類中解釋壹下check()方法。

接口IGood{//定義IGood借口。

公共函數id();

公共函數名();

公共函數price();

}

類Good實現IGood {//實現借口類。

私有$ id

private $ name

私人$價格;

public function _ _ construct ($ id,$ name,$ price){//構造函數將值傳遞給Good類。

$ this-& gt;id = $ id

$ this-& gt;name = $ name

$ this-& gt;價格= $ price

}

公共函數id() {

return $ this-& gt;id;

}

公共函數名(){

return $ this-& gt;姓名;

}

公共函數價格(){

return $ this-& gt;價格;

}//3個公共方法

}

類Cart實現ICart {//實現ICart接口類。

私人$商品;

公共函數__construct() {//將商品屬性定義為數組。

$ this-& gt;商品=數組();

}

公共函數check ($ good) {//check方法確定id值。

$ id = $ good-& gt;id();

if(isset($ this-& gt;商品[$id])) {

$ item = $ this-& gt;商品[$ id];

$ quantity = $ item[1];

返回$數量;

}否則{

返回0;

}

}

公共函數put(good,$quantity){

$ id = $ good-& gt;id();

$ num = $ this-& gt;支票($好);

$ num+= $ quantity;

$item= array($good,$ num);

$ this-& gt;商品[$ id]= $ item;

返回$ num

}

公共靜態函數check out(icart $ icart){靜態方法可以直接調用cart::check out。

}

  • 上一篇:求syn掃描的源代碼及操作系統探測的相關資料
  • 下一篇:怎樣把網頁的代碼,不讓別人在查看中的源代碼中隨便看啊?需要加上哪些代碼
  • copyright 2024編程學習大全網