ps 這裏的高級設計是針對我本身的,一開始我設計的系統,雖然實現了mvc,但尚未真正作到邏輯分離。php
由於以前開發過的訂單已經已經上線,而且運營了一段時間,修正了不少的bug。這裏給了我些思路。但我但願可以把他作的更好。mvc
我把訂單分爲了3大塊。ui
產品服務、訂單服務、結算服務、用戶服務this
<?php interface IGoodsService { public function parseGoods(); } interface ICouponsService { public function addHistory(); } interface IMemberService { function saveMoney(); } class GoodsService { } //經過接口的方式,確保OrderService可以獨立 class OrderService { protected $GoodsService; protected $CouponsService; protected $MemberService; public function __construct($GoodsService, $CouponsService, $MemberService) { if ($GoodsService instanceof IGoodsService) { $this->GoodsService = $GoodsService; } if ($CouponsService instanceof ICouponsService) { $this->CouponsService = $CouponsService; } } //新增訂單 調用他們的方法保持獨立 和邏輯的完整性 public function add($goods, $uid) { //解析產品 $this->GoodsService->parseGoods ( $goods ); //本身增長訂單 $this->MemberService->saveMoney (); //添加歷史記錄 $this->CouponsService->addHistory (); } } class CouponsService { } //執行方法 class OrderController { //新增訂單 public function add() { } public static function getOrderService() { return new OrderService ( $GoodsService, $CouponsService, $MemberService ); } }