OOP (beneficial usage)

前端 未结 3 923
南方客
南方客 2020-12-20 07:56

for my question on how to use OOP in a beneficial way I assume as an example a BASKET to which its owner (Tom) having a certain ADDRESS (NY) can add ARTICLE

3条回答
  •  悲&欢浪女
    2020-12-20 08:43

    Both basket as well as bill could have a relation to a positions item - an object representing an ordered list of zero or more items with a count and price.

    As such a list is an object of it's own it's easy to pass around:

    $bill = new Bill($buyer, $address, $basket->getPositions());
    

    However the printing of the bill should be done by the BillPrinter, because it's not the job of the bill to print itself:

    $billPrinter = new BillPrinter($bill, $printerDevice);
    $billPrinter->print();
    

提交回复
热议问题