Polymorphism
Explore polymorphism in Modern Perl to understand how objects with common method names can be used interchangeably. Learn how Moose enables efficient, maintainable code by focusing on behavior rather than inheritance. Discover how Perl's flexible approach to object interfaces allows writing adaptable functions that work across diverse classes.
We'll cover the following...
The real power of object orientation goes beyond classes and encapsulation. A well-designed OO program can manage many types of data. When well-designed classes encapsulate specific details of objects into the appropriate places, something curious happens: the code often becomes less specific. Moving the details of what the program knows about individual Cats (the attributes) and what the program knows that Cats can do (the methods) into the Cat class means that code that deals with Cat instances can happily ignore how Cat does what it does.
Common interfaces and polymorphism
Consider a function that displays details of an object: