4

I am using IntelliJ 10 Comnunity Edition, and I noticed there are two refactoring options which are similar:

-Replace constructor with factory -Replace constructor with builder

What are the differences between these two? When would I want to use over another?

Thanks

GurdeepS
  • 65,107
  • 109
  • 251
  • 387
  • 1
    Are you asking about the difference between the builder pattern and the factory pattern? They are similar patterns in that they abstract-out object creation, but they are not identical, hence the discrete commands in Idea. In any case, I'd suggest comparing the two in Wikipedia. – Kirk Woll Jan 13 '11 at 21:55
  • Whoa, you're kidding me? IntelliJ has this built in? I'm downloading trial! – Rekin Jan 13 '11 at 23:29
  • IntelliJ has A LOT of refactoring options, some of which I've never heard before, kind of makes sense as the parent company Jetbrains makes a dedicated refactoring tool (Resharper). – GurdeepS Jan 14 '11 at 00:26

1 Answers1

1

Use constructors to build an object when it can satisfy all the invariants. To understand the difference between builder and factory look this post What is the difference between Builder Design pattern and Factory Design pattern?

Community
  • 1
  • 1
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327