Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98506 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44224 invoked from network); 12 Mar 2017 13:49:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2017 13:49:36 -0000 Authentication-Results: pb1.pair.com header.from=michael.vostrikov@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=michael.vostrikov@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.176 as permitted sender) X-PHP-List-Original-Sender: michael.vostrikov@gmail.com X-Host-Fingerprint: 209.85.161.176 mail-yw0-f176.google.com Received: from [209.85.161.176] ([209.85.161.176:35632] helo=mail-yw0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/9B-38004-EE155C85 for ; Sun, 12 Mar 2017 08:49:35 -0500 Received: by mail-yw0-f176.google.com with SMTP id v198so46375720ywc.2 for ; Sun, 12 Mar 2017 06:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vWRX58MDWGqge3CdZPbS3Zy/OGIVQwnSspjGcjBaZHw=; b=LFBm7hL7GVOMxQPICEu044OAbXK54+R3lFFQ6tRD3NjPmoSIS1Vbc5bKXX0NS5AkzF nw1Ywk1XcVcHxSRMu7117NzdAFQTteEkN08KWqe65DSJKXNJak8Kcy7uztiqVz8D7neO x1kctslgKztuBShyNCS80eOUyf5XICJL6uVVypNgKfkjn/syz/vLExIHRxBOsC8jmrB8 XsfgSI4QU8k8jqnUB6O+W3rqqQLDnCeyORC5YMipWepgXYWqy91xXLAdSxvP8oaw/HfO Xbb9K9mIkOVpwgxZdlu8lNjLkVasQORV5I7nxcyPsQeiYmhrYGuFB2MaKT8sI/hVHnXM YuJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vWRX58MDWGqge3CdZPbS3Zy/OGIVQwnSspjGcjBaZHw=; b=XcjJZeOoeQwhpK9B/pw9GgFdRk0in6s8d7qcdw/J1+0dabnMJp2jgkZCqTjcK0YkbJ 3B9TfEQrpdU9Wjjqa7sL8Pn0WIXNsfJgDzepW2fZItjDgWufDuyMH68PeKSLltg2+w+d S7xzh0cTiXZaTkt0PMi4MDzlBxfoMaSSVzhxBZYQhMdoycDXxnF36cmLYj8LIzZthZnM VXVXeBqKKuZzM8/j+ZK6iZ60veht89QRv0Viczd7cSQmT/Z64//DpVKjR3QwloDrrMPG W439fPrU3Xj5aOyvvkOeumjjkGszZ21b2FfeJeaVW0tl+jeC6k66i087mCnI3LbWCjZz lnGg== X-Gm-Message-State: AMke39mikrE7GQLlnCMVfFrKXN+1gDK/vDj6+8Yyd/Vdl6XkENjFXuiJNhzZiiSfk9Opstz4JN3jX/VtVqdyMw== X-Received: by 10.129.81.80 with SMTP id f77mr14262678ywb.239.1489326571522; Sun, 12 Mar 2017 06:49:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.13.224.196 with HTTP; Sun, 12 Mar 2017 06:49:31 -0700 (PDT) In-Reply-To: <2a928258-af19-c15f-548f-eb348b3f5449@fleshgrinder.com> References: <2a928258-af19-c15f-548f-eb348b3f5449@fleshgrinder.com> Date: Sun, 12 Mar 2017 18:49:31 +0500 Message-ID: To: PHP Internals Cc: Yasuo Ohgaki Content-Type: multipart/alternative; boundary=001a114570be401759054a88dd01 Subject: Re: [PHP-DEV] Type variants From: michael.vostrikov@gmail.com (Michael Vostrikov) --001a114570be401759054a88dd01 Content-Type: text/plain; charset=UTF-8 2017-03-12 15:33 GMT+05:00 Yasuo Ohgaki : > DbC allows this kind of validation at development time. > I suppose you would like to check requirement at runtime always. Yes, DbC from here https://wiki.php.net/rfc/dbc2 describes similar things. This is good idea, but I tell more about checks which cannot be removed from code. Types which meet some requirements looks more closer to business logic terms than constructions like if-throw or require($order->isReadyForSomething()). 2017-03-12 15:35 GMT+05:00 Fleshgrinder : > `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. --001a114570be401759054a88dd01--