• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

empty Constructor vs nonEmpty

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another coworker and I were having a heated discussion about using empty Constructors, only to then invoke all the setters on the object. Can anyone explain to me if this approach makes any sense? Does this not go against the Creator pattern?

Thanks for your feedback.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There always have been two camps on that issue. However the JavaBean style of construction doesn't allow you to create immutable objects which according to Joshua Bloch's Effective Java is very desirable. JavaBeans were meant to solve one particular problem - there were never intended as the template for the ideal class.

See also:
Immutable Objects
Avoid JavaBeans style of construction

Allen Holub: Why getter and setter methods are evil
Allen Holub: More on getters and setters

Also patterns do not apply all of the time � they only apply under very particular circumstances.
Creator Pattern

Apply Patterns Gently.
 
Shannon Sims
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Peer. These are great articles! I will share these with my coworker.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic