[LA.pm] Classes with heterogeneous objects?
Ben Tilly
btilly at gmail.com
Fri Mar 2 21:22:39 PST 2012
Sure, here is a use case.
A module that uses inside out objects to store its private attributes,
which is meant to be used in a multiple inheritance situation. It
does not know, or care, what the objects it gets look like, and
different subclasses can use different data types under the hood.
That said, this is possible but not necessarily a *good* idea.
On Fri, Mar 2, 2012 at 7:22 PM, Mike MacKenzie
<mackenziemikebus at yahoo.com> wrote:
> Hi Mongers,
>
>
> Even after all these years, Perl sometimes surprises me. I just realized today that there is nothing preventing you from creating a class whose instances are implemented heterogeneously. Your constructor could return a blessed scalar sometimes, a blessed hash under other conditions and a CODE ref at other times. All would be instances of the same class. Now I just need to think of a use case for such a thing.
>
> Can any of you guys think of an interesting use case for a class that creates objects with disparate internal structures like this? Or do you know of an existing module that does this?
>
> Mike MacKenzie
>
> _______________________________________________
> Losangeles-pm mailing list
> Losangeles-pm at pm.org
> http://mail.pm.org/mailman/listinfo/losangeles-pm
More information about the Losangeles-pm
mailing list