• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Please opine

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
Please have a look at the following qs and indicate what you think to be the best answer. Please provide the explanation why you think it to be the most suitable.

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?

choices:
--------
Factory Method
Builder
Prototype
Composite
Decorartor
Abstract Factory

To me, it seems Builder is the right option, considering the 'PC' to be the complex object. However I would like your advice on this.

Thanks..
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Goutam,

I would bet on the Composite one. We want here a tree structure of simple and composite objects, and Composite does exactly that.

Regards,
Dan
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?


That means, you just can buy (1), (2), or (3) without modifications. So Prototype is your friend.

Cheers,
Harbo
[ September 12, 2004: Message edited by: H. Hafer ]
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also think as only particular combinations are valid, prototype should be the design pattern.
 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
My first answer was Builder, but after seeing the answers above I agree its prototype. The trick is to see that only 3 things can change (I didn't spot this on first read). If many things can change in a PC, then I think its Builder.

Strange that 'Core J2EE Patterns' does not mention Prototype. Maybe this is another reason people may choose Builder (depends on books read?).

Ray
 
H. Hafer
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?).


Oh, does "Core J2EE Patterns" mention Builder? I'm surprised - both are design patterns.

cheers,
Harbo
 
Ramon Gill
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harbo,
'Core J2EE Patterns' doesn't mention Builder either - why is that?
Ray
 
H. Hafer
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All those GOF-Patterns are design patterns and therefore quite low level - that is, for the design.
J2EE patterns aim at something on a higher level. So to say architectural-but-bound-to-j2ee-technology patterns.

regards,
Harbo
 
Ramon Gill
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harbo. Thanks for the explanation. Can you recommend any books other than the GOF for patterns such as prototype and builder?

Ray
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the reasons I chose the Composite design pattern is because it is a structure pattern.
The question states:

The design of which design pattern would ensure that only legal combinations could be sold?



For me the question means that we want to organize our PC set-up options in some sort of a structure which will enforce only proper combinations; meaning, a PC can have only one processor, a certain disk space and a certain RAM size.

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.

Hope it makes sense,
Dan
 
H. Hafer
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ramon,

Craig Larman, "Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process (2nd Edition)" is my favorite.

regards,
Harbo
 
H. Hafer
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


Dan,

the composite thingie is for recursive structures, AFAIK. The pattern aims at the problem on how to treat nodes and leaves with the same interface.
The example above is not recursive: the depth of the tree is, er, one :-)

HTH,
Harbo
 
Ramon Gill
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Thought I'd add some more input to this thread based on some things I've just read in, ' Applied Java Patterns'.

Page 16 states that the 'Builder' pattern is often used to produce 'Composite' objects.
Page 32 states that 'Factory' Methods often use a 'Prototype' to act as a template for new objects.

I think this shows that this no one right answer to the original question. It also shows that there's a lot of overlap between the patterns. Also, you could have answere like Dan (looking at how data is stored', or others (how to create the data).

Ray
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is Abstract Factory as you are creating a family of related products depending on the combination you choose.

Builder would have been correct if the question would have asked 'The computer can have exactly 1 processor, 1 HDD and 1 memory stick'.

Prototype specifies the kinds of objects to create using a prototypical instance. For example: Given a processor, if you were asked to create a computer that used multi processors, this would be the correct option.

Composite would be used when you want to treat the individual object and composite object as one without knowing whether you are dealing with the part or the whole. This does not seem to apply here.

Just my 2 cents...

Parag
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

You need to avoid building a class hierarchy of factories that parallels the hierarchy of objects.



But since we have only three combinations, the Builder should be fine to use.

Regards,
Dan
[ September 17, 2004: Message edited by: Dan Drillich ]
 
Parag Doshi
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]



Actually I think Abstract Factory is the right answer. As we are asked to create a family of products based on the choice of combination.

Parag
 
H. Hafer
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hm, I can't perceive the three choices as being three families, because one *could* (by choosing a more flexible reseller) take CPU from (1), HD from (2) and whatnot from (3). That's the reason, why abstract factory doesn't fit IMHO. Taking the famous abstract-factory-example: You wouldn't be able to assemble MSWindowframe, MOTIFScrollbar and PMButton into something usefull.
And you don't want to.

I don't think, that anything has to be assembled - there are three choices and thats it. So, compositional patterns would be oversized.

regards,
Harbo
 
D. Rose
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Parag,

I do not think abstract factory is correct as there are no parallel product hierarchies here.
And remember that these combinations are not implementation driven, these are only dynamic combinations and may change over the time.
So if you come up with new combination, you would have to add new class hierarchy as well as factory. While in prototype, it is just adding a concrete prototype.
It's specifically one of the applicabilities stated in GOF prototype pattern

To avoid building a class hierarchy of factories that parallels the product hierarchy

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've seen this question in the whizlabs mock exams and if I remember well their answer was Builder.
But I disagree with them, I think the correct answer is prototype because you can only purchase a clone of one of the 3 prototypes. You cannot freely combine the parts to get a new computer, so it's not a builder. And finally, your goal is not to create related parts but to get a whole computer, so it's not an abstract factory.

Richard
 
Parag Doshi
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok..here is my justification for the Abstract Factory. I am re-pasting the question:


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?



The reason for choosing AbstractFactory was that the question requires that only legal combinations are sold. The emphasis is on the "legal" or applicable combinations. So, in other words, there are 3 different combinations or "family" which can be used to create a computer. If the user chooses option 1, then the abstract factory has to create a 800 MHz Processor with a 40 GB HDD and with 128 MB RAM. Creating the appropriate processor, HDD and RAM makes the combination legal, so these are the "parts" to make a whole combination legal. Internally, it might use a factory to create the appropriate processor/HDD/RAM, but, each combination would be an abstract factory implementation, so when you add a new combination, a new abstractfactory would be created to support it.

I am not sure how the prototype or factory would validate the "legal" combinations requirement.

Thats my reason for choosing a Abstract Factory.

Parag
 
Richard Duglora�
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Parag Doshi
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Richard,
I just interpreted the question as is, I did not take the "exact" one CPU, HDD and RAM condition into consideration as I thought that the question wants to know how to create a "legal" combination rather than a "correct" combination.
The point to remember is that such questions are asked in Part I of the exam, where the language and the wordings mean everything. If it was a real life scenario, we would have asked whether the creation had any further constraints (illegal combinations etc) and applied the most appropriate pattern meeting all the conditions.


Parag
[ September 20, 2004: Message edited by: Parag Doshi ]
 
Goutam Bhattacharjee
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,
Many thanks to everybody for such overwhelming response. It's great to know the different logic and thought process put forward by so many people. However, unfortunately it makes me think that the SCEA test has really become somewhat probabilistic rather than deterministic which can frustrate many of us when we actually sit for the real exam. In real life, we could approach a problem from different angles and come up with as many effective solutions. However, the test will only recognize the answer which is programmed to be the correct one.The questions too, do not give enough information based on which you can draw the fine line between closely related solutions.
I can cite several such cases where multiple correct answers are existing. For example, in java to legacy CORBA connectivity, which protocol do you choose? When you have options as RMI-IIOP, Java-IDL and JNI Wrappers+RMI co-existing, it's difficult to make a choice. In this case, all 3 are in fact valid solutions and probably the only deciding factor is the personal liking of the architect.

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?

I am looking forawrd to hear your comments on this.
 
H. Hafer
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?


The less frustrating solution would be to just learn the examiners' taste from mock exams, passing the test and just get over it

regards,
Harbo
 
D. Rose
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gautam,

You need not worry much. Only few exam questions would be like this. So you can pass easily even if you get them wrong.
I think Sun is making things more like real life. Life is probabilistic!
[ September 21, 2004: Message edited by: D. Rose ]
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
up
 
What's gotten into you? Could it be this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic