Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Hibernate Basics Getting Started with Hibernate The Builder Design Pattern

Why not just store a Contact field in your ContactBuilder class?

Instead of copying and pasting all of the fields from your Contact object into your ContactBuilder object, why don't you just create a Contact field in ContactBuilder, instantiate it in your ContactBuilder constructor, call its setters to assign values to its properties, and return this.contact on the build call?

Simon Lammes
Simon Lammes
8,391 Points

I agree with you. Why not make it even simpler by making the setters of Contact return the contact itself? This way you could chain your "building operations" even without creating a builder. It would look like that:

Contact c = new Contact().setFirstName("Simon-Jerome").setLastName("Mรผllermeister").setEmail("simon.jerome.mรผllermeister@fakeaddress.com");