On 11/03/17 06:36, Michael Vostrikov wrote:
$rectangle = new Rectangle(0, 0, 10, 10);
drawSquare($rectangle);
When drawSquare() is called, the check 'instanceof' is performed. It calls
magic method __match().
If __match() does not return true, it throws an exception with the data
returned:
My problem here is with the reason for needing a different class for
'Square' when $rectangle->is_square() is a simple additional check on a
single Rectangle class. drawSquare() seems redundant when
$rectangle->draw() does the same job ... a lot of duplicate code for
little gain? My problem I think is 'instanceof' is being used
incorrectly here.
'Order does not match OrderForCheckout. Reason: ...'.
The class is 'Order' which in my book will be a variable list of
'LineItem' and each line item will have a status such as is_instock().
The Order status of is_shipable() flags an order that is ready for
shipment which will produce an answer of yes, partial or no.
Just as you don't need to change Rectangle->Square just because you want
to draw a square with a set of numbers which started as a Rectangle, you
don't want to change the class from Order to OrderForCheckout. The base
order simple has a set of constraints which must be met before is_ready
can apply and is_billable will flag if you only charge for a shipment,
or take a full payment with order. LineItem has a check on 'backorder'
to validate if it's allowed to add items which are out of stock.
While I think I can see the logic behind describing these as different
types of object I think it is the same mistake as strictly enforcing
'int' when the raw data you have is a string of numbers. And just
because you know you have a number for the quantity to buy you still
need to check that against the stock level and handle it differently if
there is not sufficient stock. Trying to create 'type's for all the
variants of the object is just wrong? int_instock, int_minorder,
int_backorder, int_special_production and so on as the types of LineItem
so 'instanceof' will work for you?
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php