2017-02-10 46 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 
}