2017-02-10 48 views
0

https://fsharpforfunandprofit.com/assets/img/uml-order.pngOOP PHP代碼中的1對多關係?

這是實現的類圖,但代碼中的一對多關係是什麼樣的?

這是一個文本,請計算器接受我的問題

class Customer { 

    public $name; 
    public $location; 

    public function sendOrder(){ 
      //method here 
    } 

    public function receiveOrder(){ 
      //method here 
    } 

} 

class Order { 
    public $date; 
    public $number; 

    public function sendOrder(){ 
      //method here 
    } 

     public function receiveOrder(){ 
      //method here 
     } 
    } 

class SpecialOrder Extends Order{ 
    public function dispatch(){ 
     //method here 
    } 
} 

class NormalOrder Extends Order{ 
    public function dispatch(){ 
     //method here 
    } 

    public function receive(){ 
     //method here 
    } 
} 

回答

0

類圖不會強迫任何實施多重性。所以你可以自由地實現它。最容易的最前鋒是Order陣列Customer。我的PHP很生鏽,但它可能看起來像這樣:

class Customer { 
    $orders = []; // references to orders 
    // rest of the class 
}