Jogaraj,
Welcome to Javaranch ... the above two answers were correct .. the question that we got in the yahoo group is as follows ..
Compact Computers is a small computer assembly company. Its online
application allows customers to pick and choose accessories to build their
own PCs. The accessories are:
i. Processor - 800Mhz, 1Ghz, 1.2Ghz
ii. HDD - 40 GB, 60 GB, 80 GB
iii. Memory - 128 MB, 256 MB, 512 MB
Customers choose parts and quantities during the order. For example, a
customer could choose a second HDD as a secondary hard drive or purchase
additional RAM. What design pattern may be optimal for implementing a
suitable design here?
A Factory Method
B Prototype
C Singleton
D Template Method
E Business Delegate
F Builder
here please note the statement "a customer could choose a second HDD as a secondary hard drive or purchase additional RAM"
this means .. the construction process is same but we need to vary the structure ...this I think calls for the prototyping pattern.
So moral of the story :
1 If we have a defined family of objects to build(meaning the object compostion is known at design time), go for Abstract Factoty Pattern
2.If we do not know the object composition meaning that the object compostion has to be dynamically determined , then go for a builder pattern
3.If we do not know the object composition meaning that the object compostion has to be dynamically determined and furthermore the structure of the object can change dynamically ..go for prototype.
So may be creational patterns depending on complexity go like this in the increasing order of complexity
factory -- > abstract factory --> builder --> prototype.
Singleton is a supportive pattern in this thought process. In Ramu Meda's notes I was studying that Abstract factory and prototype are somewhat competing ..and they can also be used together.An abstract factory may also store a set of prototypes from which to clone and return product objects.
Any pattern expert please comment
