2017-02-10 6 views
0

https://fsharpforfunandprofit.com/assets/img/uml-order.png코드에서 OOP 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 
}