Re: Type variants

From: Date: Sun, 12 Mar 2017 13:54:17 +0000
Subject: Re: Type variants
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-98508@lists.php.net to get a copy of this message
On 3/12/2017 2:49 PM, Michael Vostrikov wrote: > 2017-03-12 15:35 GMT+05:00 Fleshgrinder <php@fleshgrinder.com>: >> 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 > > Yes, this is Order and OrderForCheckout in my example. But they should not > be descendants of base class or each other. Because allowed class states > are not descendants of that class. > >> **BAM** all problems solved. > > Yeah, now we have: > base Order > IncompleteOrder extends Order > ProcessableOrder extends Order > PaidOrder extends Order // or ProcessableOrder? > > and later could get: > WholesaleOrder extends Order > > with a question how to extend classes in new branch. > > > Also the problem is how to use this tree in relations. > > There is class OrderItem with $order property. > There is class Customer with $orders property. > What classes should have these properties? Every time different? > > This is a part of another problem that we need to decide what exact class > should be created here or there before calling a function which uses it. > > > With type variants (hm, or invariants) it could be: > Order > ProcessableOrder variant of Order > PaidOrder variant of Order > WholesaleOrder variant of Order > > And everywhere we can create and use objects with class Order, and only in > some functions they will be considered as processable or not. > Post this on Stackoverflow and I'll give you some answers and possible approaches. ;) You are clearly struggling with architecture and design, but you are definitely not missing language constructs here. -- Richard "Fleshgrinder" Fussenegger

« previous php.internals (#98508) next »