Re: Pre-PPC: class :abstract
[email protected] (Ovid)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <CA+M4CHs6b6nNSHcU4P_T5=y=nE-31nYPrQokXu+DQHDBxEZ9eQ@mail.gmail.com> |
On Sat, Dec 20, 2025 at 5:04 AM Darren Duncan <[email protected]> wrote: > On 2025-12-19 2:59 a.m., Ovid wrote: > > For abstract classes, they have uses, too, such as being the base class > for a > > factory and ensuring that every factory class has the required > interface. They > > do have one notable fragility, though. If you add a new abstract method, > all > > subclasses are immediately broken until they can be updated. Maybe not > so bad > > for closed source work, but bad for open source. > > That problem is avoided easily enough by the abstract class having a > default > implementation, which in likely most cases would be reasonable. -- Darren > Duncan > That is a very dangerous assumption. The following is a trivial example: use v5.40.0; class StorageHandler { method connect() { say "Connecting to generic backend..."; } # If a subclass forgets to override this, the app thinks data # is being deleted when it isn't. This violates the "fail-fast" principle. method delete_all_logs($user_id) { # Doing nothing here is dangerous. return 1; } } class CloudStorage :isa(StorageHandler) { method connect() { say "Connecting to S3..."; } # Developer forgot to implement delete_all_logs! } my $storage = CloudStorage->new; $storage->connect; # The dev thinks they are clearing sensitive data: $storage->delete_all_logs($user_id); say "Cleanup complete!"; # Oops -- https://curtispoe.org/