Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Factory Method / Prototype Design Pattern

Reply
Thread Tools

Factory Method / Prototype Design Pattern

 
 
Pallav singh
Guest
Posts: n/a
 
      11-18-2008
Hi ,

when should i select Factory Method / Prototype Design Pattern
during my design phase ??
as both look similar to me

Thanks in Advance

Thanks
Pallav
 
Reply With Quote
 
 
 
 
yuvalif@gmail.com
Guest
Posts: n/a
 
      11-18-2008
On Nov 18, 8:29*am, Pallav singh <(E-Mail Removed)> wrote:
> Hi ,
>
> when should i select * Factory Method / Prototype *Design Pattern
> during my design phase ??
> as both look similar to me
>
> Thanks in Advance
>
> Thanks
> Pallav


IMHO, you should find a pattern for a problem and not a problem to a
pattern
 
Reply With Quote
 
 
 
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      11-18-2008
On Nov 18, 1:29*pm, Pallav singh <(E-Mail Removed)> wrote:
> Hi ,
>
> when should i select * Factory Method / Prototype *Design Pattern
> during my design phase ??
> as both look similar to me


Factory Method creates a new object. Normally, it invokes a (non-copy)
constructor of a concrete implementation class.

Prototype create a new object as a copy of the prototype object. It is
often implemented as clone() member function that invokes the copy
constructor of a concrete implementation class.

You use Factory Method when you want new objects, prototype when you
want copies of existing objects.

--
Max
 
Reply With Quote
 
Pallav singh
Guest
Posts: n/a
 
      11-18-2008
On Nov 18, 6:36*pm, Maxim Yegorushkin <(E-Mail Removed)>
wrote:
> On Nov 18, 1:29*pm, Pallav singh <(E-Mail Removed)> wrote:
>
> > Hi ,

>
> > when should i select * Factory Method / Prototype *Design Pattern
> > during my design phase ??
> > as both look similar to me

>
> Factory Method creates a new object. Normally, it invokes a (non-copy)
> constructor of a concrete implementation class.
>
> Prototype create a new object as a copy of the prototype object. It is
> often implemented as clone() member function that invokes the copy
> constructor of a concrete implementation class.
>
> You use Factory Method when you want new objects, prototype when you
> want copies of existing objects.
>
> --
> Max


Hi

i could not make any diffrence from implementation provided by Huston
Design pattern
http://www.vincehuston.org/dp/

from Gang of Four i got Idea to use under Certain Condition

1. Factory
A class hierarchy of factories that parallels the class hierarchy
of products
Parallel class hierarchies result when a class delegates some of
its responsibilities
to a separate class.

2. Prototype

when instances of a class can have one of only a few different
combinations
of state. It may be more convenient to install a corresponding
number of
prototypes and clone them rather than instantiating the class
manually,
each time with the appropriate state.

Does it mean that i should we protoype when i have to make object
at Run Time
depending upon different combinations of state ???

Thanks
Pallav
 
Reply With Quote
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      11-18-2008
On Nov 18, 2:11*pm, Pallav singh <(E-Mail Removed)> wrote:
> On Nov 18, 6:36*pm, Maxim Yegorushkin <(E-Mail Removed)>
> wrote:
>
>
>
> > On Nov 18, 1:29*pm, Pallav singh <(E-Mail Removed)> wrote:

>
> > > Hi ,

>
> > > when should i select * Factory Method / Prototype *Design Pattern
> > > during my design phase ??
> > > as both look similar to me

>
> > Factory Method creates a new object. Normally, it invokes a (non-copy)
> > constructor of a concrete implementation class.

>
> > Prototype create a new object as a copy of the prototype object. It is
> > often implemented as clone() member function that invokes the copy
> > constructor of a concrete implementation class.

>
> > You use Factory Method when you want new objects, prototype when you
> > want copies of existing objects.

>
> > --
> > Max

>
> Hi
>
> i could not make any diffrence from implementation provided by Huston
> Design patternhttp://www.vincehuston.org/dp/
>
> from Gang of Four i got Idea to use under Certain Condition
>
> 1. Factory
> * *A class hierarchy of factories that parallels the class hierarchy
> of products
> * *Parallel class hierarchies result when a class delegates some of
> its responsibilities
> * *to a separate class.


In the original question you mentioned Factory Method design pattern.
Now you are quoting Factory. Huh?

>
> 2. Prototype
>
> * *when instances of a class can have one of only a few different
> combinations
> * *of state. It may be more convenient to install a corresponding
> number of
> * *prototypes and clone them rather than instantiating the class
> manually,
> * *each time with the appropriate state.
>
> * *Does it mean that i should we protoype when i have to make object
> at Run Time
> * *depending upon different combinations *of state ???


It depends on the problem at hand. Do you have a concrete problem in
mind?

--
Max
 
Reply With Quote
 
Michael DOUBEZ
Guest
Posts: n/a
 
      11-18-2008
Pallav singh a écrit :
> On Nov 18, 6:36 pm, Maxim Yegorushkin <(E-Mail Removed)>
> wrote:
>> On Nov 18, 1:29 pm, Pallav singh <(E-Mail Removed)> wrote:
>>
>>> Hi ,
>>> when should i select Factory Method / Prototype Design Pattern
>>> during my design phase ??
>>> as both look similar to me

>> Factory Method creates a new object. Normally, it invokes a (non-copy)
>> constructor of a concrete implementation class.
>>
>> Prototype create a new object as a copy of the prototype object. It is
>> often implemented as clone() member function that invokes the copy
>> constructor of a concrete implementation class.
>>
>> You use Factory Method when you want new objects, prototype when you
>> want copies of existing objects.

>
> i could not make any diffrence from implementation provided by Huston
> Design pattern
> http://www.vincehuston.org/dp/



At the end of the page you provided, the "Rules of thumb" section gives
hints about the forces involved.

>
> from Gang of Four i got Idea to use under Certain Condition[snip]
>
> Does it mean that i should we protoype when i have to make object
> at Run Time
> depending upon different combinations of state ???


No. Prototype is especially useful when the objects requires some
initialization of state or when the clones share a common data.

IMHO the best is to start with a simple factory function and refactor if
needed. If you really think you may need an abstract factory or a
prototype system, you may use a policy-based design as presented by
Alexandrescu but it does add complexity.


--
Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
Abstract factory and Factory pattern C# ASP .Net 4 07-31-2008 03:22 PM
May I have a example of design pattern of "composite", I still feel fuzzy after reading book of Addison-Wesley's"design pattern " jones9413@yahoo.com C++ 1 08-31-2007 04:09 AM
documents related to factory design pattern and Abstract foctory pattern. sunny C++ 1 12-07-2006 04:26 AM
Abstract Factory or Factory Method pattern question.... Medi Montaseri C++ 17 09-03-2003 06:50 AM



Advertisments