«« Next » « Previous
«« Next » « Previous

Link Details

Announcement

iPhone DZone: Fresh Links On Your iPhone by matt at Sat Jul 05 14:09:51 EDT 2008

Reading DZone on your iPhone just got a little bit easier. Visit http://dzone.com/iphone from your iPhone to try out our beta iPhone support. You can view stories, filter by tags, and login. We'd appreciate your feedback at feedback@dzone.com.

Vote early, vote often! When you help pick the links, you'll like DZone better. Login and vote now.
Link 79376 thumbnail

By bloid
via reiersol.com
Published: May 06 2008 / 07:32

Everybody who writes object-oriented code knows about constructors. You need them so the program knows how to instantiate objects, right? And you especially need them when a lot of things have to be done while instantiating an object. And personally, I've never considered visibility restrictions important enough to be a major argument against those languages that have lacked them (PHP 4). So why would I be skeptical of public constructors?
  • 6
  • 12
  • 1356
  • 594

Comments

Add your comment
User 244651 avatar

jakyra replied ago:

0 votes Vote down Vote up Reply

An interesting way to get around not being able to overload functions, at least at the constructor level.

User 233461 avatar

antych replied ago:

1 votes Vote down Vote up Reply

I would consider those factory methods to be a supplement for a standard model, use them where appropriate. Limiting access to any method, not just constructor without a good reason makes your code less testable. btw. you can use "new self()" inside that static call.

User 254602 avatar

nwbrown replied ago:

1 votes Vote down Vote up Reply

Sure, there are plenty of times where factory methods are better than public constructors. But to make the leap from that to "{0} considered harmful" is a bit of a stretch.

User 273110 avatar

isnoop replied ago:

1 votes Vote down Vote up Reply

Useful? Perhaps...
Harmful? Hardly.

No need for the hysterics.

User 281687 avatar

paul_houle replied ago:

0 votes Vote down Vote up Reply

A good blog post with a poor title. There are many cases where static "create" methods or Factory objects make sense.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.