Revision: 10820
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 14, 2009 17:09 by narkisr
Initial Code
public class RadioBuilder { private int buttons; private CDPlayer cdPlayer; private MP3Player mp3Player; public static RadioBuilder create() { return new RadioBuilder(4, CDPlayerBuilder.create().build(), MP3PlayerBuilder.create().build()); } public RadioBuilder(int buttons, CDPlayer cdPlayer, MP3Player mp3Player) { this.buttons = buttons; this.cdPlayer = cdPlayer; this.mp3Player = mp3Player; } public RadioBuilder withButtons(int buttons) { return new RadioBuilder(buttons, cdPlayer, mp3Player); } public RadioBuilder with(CDPlayer cdPlayer) { return new RadioBuilder(buttons, cdPlayer, mp3Player); } public RadioBuilder with(MP3Player mp3Player) { return new RadioBuilder(buttons, cdPlayer, mp3Player); } public Radio build() { return new Radio(buttons, cdPlayer, mp3Player); } }
Initial URL
Initial Description
An immutable (a new object is created for each change) Java class builder pattern example.
Initial Title
An immutable Java class builder
Initial Tags
java
Initial Language
Java