Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Leaving a constructor midway?

by oylee (Pilgrim)
on Oct 22, 2003 at 16:32 UTC ( [id://301274]=note: print w/replies, xml ) Need Help??


in reply to Re: Leaving a constructor midway?
in thread OO: Leaving a constructor midway?

I think it's just a distinction between a factory method and a constructor. Perl gives you factory methods. You have to explicitly return your 'object' at the very end of your 'constructor'. Whereas the traditional notion of a constructor is something that implicitly returns itself and all you need to do is ensure that your object is in a suitable initial state.

Factory methods are just as flexible though and I usually favor them over constructors anyway since they give you a lot more control over what specific object you are creating. For instance, a factory method can create and return a specific subtype of the object you want and you can swap out that specific subtype (to change underlying implementation) easily without breaking client code. Similarly with turning a class into a singleton.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found