I've just read a fantastic example of a builder pattern.
In my program I'm creating a series of playerCharacter entities, which can be constructed in various ways, with some compulsory fields and some that can be added on as extra or added latter on (after construction). So, after reading the above post, it seems as though I need a builder pattern.
Do I have the option of the builder and super class (here, in the example Pizza
and builder
) sharing some of the methods? Is there a neat, known solution to this?
For instance if, in the above example (of the pizza), at a later time we had a method of Boolean isPizzaCold()
and void heatTo(int degrees)
and we wanted the pizza to return false to start with, as it's 'built' hot, and later to let the pizza 'get cold', so that it cools. How would I do this such that they share the same methods?
[edit: as per Joeri's suggestion I've changed the method example.]