On 3/12/2017 10:36 AM, Michael Vostrikov wrote:
> Now we need to write in business logic the following:
> 
> function checkout(Order $order)
> {
>     if (count($order->products) > 0) {
>         throw new SomeException1();
>     }
>     if ($order->date === null) {
>         throw new SomeException2();
>     }
>     if ($order->address === null) {
>         throw new SomeException3();
>     }
> 
>     // checkout steps
>     ...
>     someActionWithOrderForCheckout($order);
>     ...
> }
> 
> function someActionWithOrderForCheckout(Order $order)
> {
>     if (count($order->products) > 0) {
>         ...
>     }
>     if ()
>     ...
> }
> 
> 
> Of course, we can move all checks to some function like
> 'ensureOrderIsReadyForCheckout()' and call it everywhere manually.
> But this is the same as call is_integer() manually instead of type hinting.
> 

The problem you are facing is that you are dealing with an anemic domain
object that does not enforce its own invariants. Properly applying OOD
principles would remedy all your problems. However, you do not require
new features to do that.

-- 
Richard "Fleshgrinder" Fussenegger

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to