Re: Type variants
| From: | Fleshgrinder | Date: | Sun, 12 Mar 2017 10:35:45 +0000 |
| Subject: | Re: Type variants | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98504@lists.php.net to get a copy of this message | ||
On 3/12/2017 11:29 AM, Michael Vostrikov wrote:
> 2017-03-12 14:58 GMT+05:00 Fleshgrinder <php@fleshgrinder.com>:
>> The problem you are facing is that you are dealing with an anemic domain
>> object that does not enforce its own invariants.
>>
>
> Incomlplete order with date and address not set yet is a valid state of
> order.
> Also, there are many cases when logic which includes many objects is placed
> in a service and not in any of that objects.
Sure, but you should still not have an anemic domain. Any object needs
to ensure its own invariants, that's nothing another service should do.
You are clearly dealing with two kinds of orders, hence, create two
kinds of orders.
IncompleteOrder is the one without date, address, and
probably even products. You directly named it as such. Then you have
ProcessableOrder where this is impossible. **BAM** all problems solved.
On 3/12/2017 11:29 AM, Michael Vostrikov wrote:
> 2017-03-12 14:58 GMT+05:00 Fleshgrinder <php@fleshgrinder.com>:
>> However, you do not require new features to do that.
>
> I don't tell that we cannot make that with current features. I suggest a
> way to do that more easy. This is like type hinting. We can check types
> manually by calling functions like is_integer() or get_class(), but we
> don't have a question why we need to have type hinting in language.
The problem is that your proposal is meant to solve problems that are
already solved in a way that is not really understood by anyone so far.
--
Richard "Fleshgrinder" Fussenegger