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

Link Details

Good things come to those who vote! Login and vote now.
Link 96273 thumbnail

By bloid
via phpimpact.wordpress.com
Published: Jul 19 2008 / 22:46

Normally, creating an instance of a class is done by calling new, which calls the constructor. Static factory provides a static method that returns an instance of the class. So, you are using static factory instead of the constructor. Providing a static factory method instead of a public constructor has both advantages and disadvantages.
  • 6
  • 2
  • 1147
  • 315

Comments

Add your comment
User 274254 avatar

ARGibson replied ago:

0 votes Vote down Vote up Reply

Hmm the "Public constructors considered harmful" link in the post is considered harmful by Firefox 3, I like the irony. (The Google SafeBrowsing report for the site doesn't look very favourable).

Anyway, isn't a Static factory effectively just the singleton pattern with a new name? Now in the course of my development activities (which span, PHP 4/5, .NET and Java) I have used factories quite a bit to control the instantiation of an object, wrapping the constructor up behind it, but I can't honestly say the constructor is a bad thing in my experience.

Maybe my views are biased by being surrounded by full object-oriented languages all day rather than PHP, but a lot of the concepts translate clearly across. Why complicate or restrict something that is proven to work and has become the given standard way of completing a task?

Maybe I missed the point.

User 292525 avatar

scriptone replied ago:

-2 votes Vote down Vote up Reply

yeah you did.

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.

Voters For This Link (6)



Voters Against This Link (2)