Re: copy contructor
- From: anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel)
- Date: 17 Jul 2005 23:11:46 GMT
Abigail <abigail@xxxxxxxxxx> wrote in comp.lang.perl.misc:
> Moritz Karbach (moritz.karbach@xxxxxxx) wrote on MMMMCCCXXXVI September
> MCMXCIII in <URL:news:db8ihi$d616$1@xxxxxxxxxxxxxx>:
> [] >> I'm writing some code in object oriented Perl, and I'm missing a default
> [] >> copy constructor. Are there some default workarounds?
> [] >
> [] > Huh? Standard OO doesn't know about copy constructors. They come
> [] > into play with operator overloading, but even then you don't necessarily
> [] > have to define one.
> []
> [] You're right. But IIRC at least C++ copies all attributes (or class members
> [] or how you call it) of a class, if you say
>
> Yeah, C++ has. But then, C++ has attributes, Perl doesn't. Perl has the
> least language support I've ever seen for doing OO - it doesn't even have
> attributes.
>
> And the step from "no attributes" to "no functionality to copy attributes"
> is trivial.
>
>
> My advice: if you really want to do OO, use a different language.
The problem isn't so much that real OO couldn't be done in Perl, but
that what the language lacks in support must be supplied by the programmer,
and it can be supplied in various incompatible ways. This is a point
where Perl's TIMTOWTDI becomes a problem.
A lot would be gained if the role of accessors in Perl OO were better
appreciated. Any method that de-references its object is an accessor,
and an (inheriting) client class may have to override all of them. So it
needs to know which they are, and it is good to restrict them in number.
Usually that only means to define a few field accessors in the usual way,
and then *base all other methods on them*. There is much so-called Perl OO
code about that accesses the object all over the place and is almost
impossible to inherit from. More complex accessors are sometimes wanted
for efficiency or flexibility. They must be clearly documented so that
a client class knows how to override them.
A parent class that is designed (and maintained) to these principles
can be safely and relatively painlessly inherited from even across
changes in implementation.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.
- Follow-Ups:
- Re: copy contructor
- From: Abigail
- Re: copy contructor
- References:
- copy contructor
- From: Moritz Karbach
- Re: copy contructor
- From: Anno Siegel
- Re: copy contructor
- From: Moritz Karbach
- Re: copy contructor
- From: Abigail
- copy contructor
- Prev by Date: Re: copy contructor
- Next by Date: Re: copy contructor
- Previous by thread: Re: copy contructor
- Next by thread: Re: copy contructor
- Index(es):
Relevant Pages
|