In bruce eckel book, builder pattern returns a product which can be Book or Magazine or WebSite . all having a parent Media Type. This makes sense to me. So in builder class, return type points to Media (parent) rather than specific child class like Book or Magazine or WebSite when i was trying to do a sample excercise, in which one Builder that puts the words into a java.util.TreeSet, and another that produces a word count to java.util.HashMap my question: One builder returns TreeSet , another builder retruns HashMap how do I map to a common base product. I want to do something similar to Media -- Magazine, Web, Book. where Media is shown as Return type in each Builder class
Introducing a common base type only makes sense if the product needs to be processed by common code. In that case what it should look like would heavily depend on how it gets used. Otherwise, you could simply declare Object as return type or even don't declare a common query method at all.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad: