Back to Browse

[Effective Java] [Item 2] Consider a builder when faced with many constructor parameters

2.5K views
Feb 20, 2019
12:01

- Telescoping constructor pattern - does not scale well! - unreadable, prone to hard to debug errors - JavaBeans pattern - allows inconsistency, mandates mutability - invariance cannot be maintained - maintaining thread safety of the class difficult - Builder pattern - safe and readable - Parameter validation can be done while object construction - Can have multiple varargs parameters - Builder pattern is flexible - Builder whose parameters have been set makes a fine Abstract Factory Disadvantages - Creating a builder object may be costly in some performance critical situations - It is more verbose than telescoping constructor pattern Summary - Builder pattern is a good choice when designing classes whose constructors or static factories would have more than a handful of parameters

Download

1 formats

Video Formats

360pmp415.4 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

[Effective Java] [Item 2] Consider a builder when faced with many constructor parameters | NatokHD