Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Perl OOP

by Arunbear (Prior)
on Jul 06, 2017 at 16:56 UTC ( [id://1194389]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^5: Perl OOP
by pryrt (Abbot) on Jul 06, 2017 at 18:04 UTC

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found