gb
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Originally posted by Goutam Bhattacharjee:
qs: A computer assembling company sells PC(s) with the following combinations:
1. 800 MHz Processor, 40 GB HDD, 128 MB RAM
2. 1 GHz,60 GB,256 MB
3. 1.2 GHz,80 GB,512 MB
The design of which design pattern would ensure that only legal combinations could be sold?
Originally posted by Ramon Gill:
Strange that 'Core J2EE Patterns' does not mention Prototype. Maybe this is another reason people may choose Builder (depends on books read?).
The design of which design pattern would ensure that only legal combinations could be sold?
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Originally posted by Dan Drillich:
I thought that we can have a Composite tree structure with three branches, one for each hardware choice and when we traverse the tree - top down, we can only reach one of the choices.
You need to avoid building a class hierarchy of factories that parallels the hierarchy of objects.
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Originally posted by Dan Drillich:
I agree with Parag � in our case the three combinations are well defined and therefore I would go with the Builder.
In case of Builder we'll need, I guess, to create three concrete creator classes and three concrete product classes.
Probably we can consider using the Prototype as one of its applicable scenarios is:
But since we have only three combinations, the Builder should be fine to use.
Regards,
Dan
[ September 17, 2004: Message edited by: Dan Drillich ]
To avoid building a class hierarchy of factories that parallels the product hierarchy
qs: A computer assembling company sells PC(s) with the following combinations:
1. 800 MHz Processor, 40 GB HDD, 128 MB RAM
2. 1 GHz,60 GB,256 MB
3. 1.2 GHz,80 GB,512 MB
The design of which design pattern would ensure that only legal combinations could be sold?
Originally posted by Richard Duglora�:
Parag
I agree that at first glance AbstractFactory could be used, with each family representing a type/model of computer, and parts being the CPU, HDD and RAM. Once you have choosen a factory for a certain model, you wouldn't be able to create illegal parts.
But you want to build a computer composed of exactly one CPU + one HDD + one RAM, not parts individually. The AF pattern controls that you can create only legal parts, but doesn't control the number of parts nor their composition, so you can create say a computer with 5 CPU + 2 HDD + 0 RAM, which is not what you want to get.
OTOH, with the prototype pattern, you would have 3 prototypes representing the 3 possible computer models (each made of a specific combination of CPU, HDD & RAM), and building a new computer would simply consist in copying/cloning one the prototypes, very much like in the industry. This way, it's impossible to build an illegal system.
Richard
gb
Originally posted by Goutam Bhattacharjee:
In my view, either the test should revoke this sort of questions or provide more specific clue to help us identity the one & only correct answer.
Is there any way we can convey this message to the examiners?
SCJP,SCWCD,SCMAD,OCP9I, SCEA
What's gotten into you? Could it be this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|