Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Perl OOP

by tobyink (Abbot)
on Jul 05, 2017 at 17:07 UTC ( #1194283=note: print w/replies, xml ) Need Help??

in reply to Re^2: Perl OOP
in thread Perl OOP

But the OP was asking about how (as an author) they can stop their classes from being subclassed. I think this is totally legitimate from a design point of view

I think it's as legitimate as asking how I, as a car manufacturer, can stop the people who buy my cars from hanging fuzzy dice from the rear-view mirror. Or how I can stop them from keeping their muddy boots on the back seat.

It's none of my damn business. If I don't want them doing that, I shouldn't sell the car. If I really need the sale, but still don't want them doing it, I can document that it voids the warranty for their expensive leather seats.

Replies are listed 'Best First'.
Re^4: Perl OOP
by Arunbear (Prior) on Jul 06, 2017 at 16:56 UTC
    You're confusing the regular use of an object (which no one is arguing against) with modular design of an object (to use inheritance or not).

    The analogy you gave would be relevant to this discussion if it had any semblance to design by inheritance, but it doesn't.

    But staying in the realm of car manufacture, we build cars by composing them out of components.

    Let's say you want to build (using 'inheritance') a new SmartLandRover that has additional sensors to detect when the driver is drunk, but 'inherits' other functionality from a base model Land Rover.

    SmartLandRover doesn't have a battery, so it must have wires connecting it to BaseLandRover so it can get power.

    SmartLandRover also doesn't have an engine, so it must have a shaft connecting it to the drive shaft of BaseLandRover so it can get movement.

    This may seem ridiculous, but we do something quite similar when we use inheritance.

    No one designs or builds cars like that, and with good reason.

      I like your LandRover analogy. In that system, my interpretation of the spirit of tobyink's analogy becomes: I buy a LandRover, and want to create a LandRover::PryrtMod, wherein I plug in an OBDII unit into the standard OBDII slot of my LandRover, so that I can look at some of the sensor data that they don't provide using my smartphone app. Or similarly, years ago, I bought a Mazda::RX8 v2005; in the intervening time, backup cameras became the norm on newer cars, so I bought an aftermarket backup camera, and created the Mazda::RX8::PryrtBackupMod which inherited the full Mazda::RX8 object, but just added the callback Mazda::RX8::PryrtBackupMod::enableBackupCam(), and I registered that callback for use inside Mazda::RX8::changeGear(). I understood when I made Mazda::RX8::PryrtBackupMod that it could possibly void any warranty, but I was able to weigh the risks vs. benefits and make an informed engineering decision. Mazda, as the manufacturer, can discourage people from trying to subclass their vehicles, and can void warranties if their product is inappropriately modified; but at some point, car hackers will find a way to subclass a vehicle with aftermarket modifications. Similarly, a Perl hacker will often be able to figure out how to subclass and add functionality to your "immutable object" class.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1194283]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-10-15 10:38 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (82 votes). Check out past polls.