Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114243 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58559 invoked from network); 28 Apr 2021 16:43:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Apr 2021 16:43:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1C6F51804E2 for ; Wed, 28 Apr 2021 09:47:54 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 28 Apr 2021 09:47:53 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id j4so60830528lfp.0 for ; Wed, 28 Apr 2021 09:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hZ19iSLYu7ED+FqOP9Nwnzi0Jsiowi2fmN7mJGfxxz0=; b=MZZqkYHbpJioym4c8tYBe+YTHIfukJGO9O/NfDzY3KXxkypZnBu2W9UReHAl9RxX1x 5Pk9e9Wq/5f76GFMpVUifhvcufJ5Hly+zso6jRDc/kpCR6RKRC2DKM/1z/fURczoVI4m 19c5BNnCTQTIUAGnI2kTD+HkRwSrfRV1xZcPTCT1ssVADX8sbb9Bo3CC2AdQVPbNEZ3G MdGNDJ56+LfYKPJ2s1lsqvlej2L3Yb4QxAleYD8hBiaOwlnjVt5VoDrkknnayhbsOAFq 0UlhexFc17wHtlMENJAYVbUw0rsr/2YglhvIyTeg9uBhcyoVJOk4jP+NsQazN9GX5hYa MREA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hZ19iSLYu7ED+FqOP9Nwnzi0Jsiowi2fmN7mJGfxxz0=; b=IYR8r4JepSRycYfv3wDW5K1BTAzhcU7yfaYpmyF90JEMeDuGmBCWShDYEdnzI9aO3z HQhuMI/wo+jqYtpllTfXFOyTkb1heMf2TcHOqG8AVGd3jFQvdkbLxxrjvVbOexMlgskR Zw/SeEKfh2YSStvEd7rSc5mq1SEEqM/z8KqPcJCKG+SPwPjXhjMCoaD1JW1jX3w/sb69 W8xGGGHikpIWbBAo5BCWe3SKlN+4oVIhQjnotcBessmXLgOP4txdYv4G5ScAVMPpyfEC cy78Rt/R/UihC/rXSvJsJy9KIdc9l28QglWcCJ/pJWKIm80CLwQ7wzdXVPTmH0PRYrL7 5cww== X-Gm-Message-State: AOAM532tD1UwLpkaHYM7sP5UM6NPqwKSb19NwL93CPuA55Y3Q2TWHKyu AgsaLZrxpQtOVRhitPFffTxTd51oz7UUeXxmmA== X-Google-Smtp-Source: ABdhPJzVXDVgurpfgMMYl5jWXq0xVSYo44f/Blivp4DEiev3D1ErvMMoRZTmoEGHgRCRYhTrD95hfEDgT7yU/rvUf2I= X-Received: by 2002:a05:6512:2151:: with SMTP id s17mr21705673lfr.119.1619628471348; Wed, 28 Apr 2021 09:47:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 28 Apr 2021 18:47:41 +0200 Message-ID: To: Tony Marston Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000b3f1eb05c10b2341" Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: guilliam.xavier@gmail.com (Guilliam Xavier) --000000000000b3f1eb05c10b2341 Content-Type: text/plain; charset="UTF-8" Re-forwarding to the list (please stop replying to me in private, thanks). Also re-answering but I will stop there because that's too much digression for a partial quote of my initial message. On Wed, Apr 28, 2021 at 5:30 PM Tony Marston wrote: > On 28/04/2021 14:30, Guilliam Xavier wrote: > > Forwarding to the list, and answering: > > > > On Wed, Apr 28, 2021 at 9:51 AM Tony Marston > > wrote: > > > >> On 27/04/2021 17:22, Guilliam Xavier wrote: > >>> On Sat, Apr 24, 2021 at 12:55 PM Saif Eddin Gmati < > azjezz@protonmail.com > >>> > >>> wrote: > >>> > >>> > >>> To me the first sentence of the RFC is debatable: > >>> > >>>> The purpose of inheritance is code reuse, for when you have a class > that > >>>> shares common functionality, and you want others to be able to extend > it > >>>> and make use of this functionality in their own class. > >>> > >>> That sounds like [abstract] base classes, which certainly permit that, > >> but > >>> I wouldn't state that "the purpose" of [designing] class hierarchies is > >>> "code reuse", which can also (better?) be achieved with traits or even > >>> simply composition > >> > >> I completely disagree that the first sentence of that RFC is debatable > >> as I consider it to be totally accurate. When you use inheritance via > >> the 'extends' keyword then every method in the superclass is shared by > >> the subclass. In the subclass you have the option to override the > >> implementation of any method in the superclass, or you can add new > >> methods of your own. > > > > > > But does that necessarily mean that "The purpose of inheritance is code > > reuse"? > > Can you show me any description of OOP which says that the purpose of > inheritance is anything other than code reuse? I suspect it won't convince you but you can find quotes like: "The point of inheritance is to take advantage of polymorphic behavior NOT to reuse code, and people miss that, they see inheritance as a cheap way to add behavior to a class." (not that I endorse it absolutely, but that's an example of different opinion). What other purose could > it possibly serve? > Modeling a problem domain? Enforcing a contract? > > This superclass may be abstract, but it need not > >> be. The methods it contains may be abstract, but they need not be. > >> > > > > I didn't say that they need (the brackets meant "optionally"). And does > it > > really matter actually? > > Yes. If you inherit any abstract methods you are not actually inheriting > anything. Not only do you have to manually define in the subclass any > method which is defined as abstract, you also have to provide the > implementation. > My bad, I should have inserted the reply one sentence earlier: I was referring to "[abstract] base classes" (from my original quote), not abstract methods. Of course if the goal is to share implementation there must be concrete methods in the base class... > >> According to the Gang of Four the way to avoid the problems caused by > >> the overuse of inheritance is to only inherit from an abstract class, > >> which is precise what I do. I am famous for having an abstract table > >> class in my framework which contains hundreds of methods and thousands > >> of lines of code, and because each of my 400 concrete table classes > >> inherits from the same abstract table class that is a LOT of code which > >> is shared. This abstract table class also allows me to use the Template > >> Method Pattern (which is mentioned in the Gang of Four book) so that all > >> the invariant methods are defined in the abstract class which means that > >> each subclass need only contain the variable "hook" methods for which it > >> needs to provide an implementation. > >> > > > > Well, PHP is flexible. I have seen many combinations of (one or several > of) > > interface, [abstract] class, trait, composition... depending on the > context. > > The fact that there are now several ways of reusing code does not > detract from the original statement that "The purpose of inheritance is > code reuse". > See above, plus a quick web search for things like "inheritance misuse" or "class SplStack extends SplDoublyLinkedList" I think shows it's a controversial subject (hence "debatable" at least). > >> When you say that code reuse can be better achieved with traits or > >> object composition I have to disagree. > > > > > > I said "also (better?)", not just "better". But one can think "no" to > > "better?" ;) > > > > > > Object composition is used only > >> by those idiots who overuse inheritance, > > In the GoF book on design patterns, which was first published in 1995, > it quite clearly stated that any problems emanating from inheritance > were causes by its overuse, and that a solution would be to only ever > inherit from abstract classes. "class Stack extends AbstractList" is still wrong. If people are still overusing inheritance > 25 years later and ignoring the advice given by the Gang of Four then I > feel justified in calling them idiots. > :/ > > and there is no evidence that > >> traits are "better" than inheritance. > > > >> By the way, is there evidence to the contrary? (genuine question) > > Until somebody does a comparison of all the different ways in which code > can be shared there can never be a definitive answer. > Agreed. > >> Inheritance, when used sensibly, is still the best way to share code. > >> > > > > Your opinion, maybe not unanimity (nor absolute truth). > > The GOF book says so, and it also says that the Template Method Pattern > - which can only be used through inheritance - is a fundamental > technique for code reuse. Are The GoF Book opinions (still) unanimity? Also, did PHP traits exist in 1994? (rhetorical questions) (and BTW, I know, composition did already exist, but not the point) In my humble opinion any method of code reuse > which does not allow the Template Method Pattern is automatically inferior. > You said it: "in [your] humble opinion" :) I have mine too. Anyone can (obviously). More importantly, even if I were to agree that "inheritance" be the best method of "code reuse" (and I have to admit it is widely used like that), I still wouldn't state that that's "the [absolute and only] purpose" of it. > Regards, > > Tony Marston > Regards, -- Guilliam Xavier --000000000000b3f1eb05c10b2341--