2017-02-10 16 views
0

https://fsharpforfunandprofit.com/assets/img/uml-order.png1 для многих отношений в ООП PHP в коде?

Это классическая диаграмма, но как выглядят отношения «один ко многим» в коде?

Это текст, пожалуйста, StackOverflow принять мой вопрос

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 
}