Introduction: The Current State of Play
Perl has "very minimal" support for object-oriented (OO) programming out of the box by its own admission. It's class-based but classes are just packages used differently. Objects are just data structures blessed into a class, methods are just subroutines whose first argument is an object or class name, and attributes/properties are often just the key-value pair of a hash stored in the object. (This last is a feature shared with JavaScript, whose prototype-based objects are just collections of key-value pairs with the keys addressed as properties.) You've got polymorphism, inheritance, and it's up to you to enforce encapsulation.
This can take a lot of work to use effectively. To help address that, several systems have been developed over the years to reduce boilerplate and provide modern (or "postmodern") OO features that developers from other languages expect. My favorite for a while has been Moo: it's got the features I need 90% of the time like built-in constructors, roles (an alternative to composition through inheritance), attributes, type validation, and method modifiers for enhanced polymorphism. And if I need to dig around in the guts of classes, attributes, and the like I can always upgrade to Moo's big brother Moose and its meta-object protocol with minimal effort.
from DZone.com Feed https://ift.tt/3rRmOEy
No comments:
Post a Comment