
- Forum
- Testing
- Software Patterns
- Factory Pattern
Factory Pattern
This is a discussion on Factory Pattern within the Software Patterns forums, part of the Testing category; Is this bad code? (C#) I was under the impression that this is like a simple factory pattern, but I ...
-
04-13-2004, 01:33 PM #1Jimbo Guest
Factory Pattern
Is this bad code? (C#)
I was under the impression that this is like a simple factory pattern, but
I now have my doubts (please ignore the lack of vallidation etc...)
void main ()
{
string s = "";
ProductFamily pf = new ProductFamily();
s = someUserInputString();
pf.getProductType(s);
pf.doSomePolyMorphicStuff();
}
public class ProductFamily
{
public ProductFamily()
{
}
public ProductFamily getProductType(string _prod_line_id)
{
ProductFamily productFamily;
return ProductFactory.getProductFamily(_prod_line_id);
}
}
public class ProductFactory
{
public ProductFactory()
{
}
public static ProductFamily getProductFamily(string productLine)
{
switch(productLine)
{
// end caps -- all the same
case "Insulating End Caps":
case "Conductive End Caps":
EndCap ec = new EndCap(productLine);
return ec;
// breakouts -- all more or less the same dimensions wise
case "3 Way Conductive Breakout":
case "2 Way Low Voltage Breakout":
BreakOut boot = new BreakOut(productLine);
return boot;
// all tubes, they are basically the same dimensions
case "Clear Insulating Tube":
Tube tube = new Tube(productLine);
return tube;
// boots -- inline and right angle are different
case "Inline Boots":
InlineBoot inBoots = new InlineBoot(productLine);
return inBoots;
}
}
}
How would I implement this with the factory or would that not be the
correct pattern to use?
-
04-18-2004, 11:14 PM #2EventHelix.com Guest
Re: Factory Pattern
> How would I implement this with the factory or would that not be the
> correct pattern to use?
Factory is the correct pattern to use here. The following article
might
help:
http://www.eventhelix.com/RealtimeMa...ce_pattern.htm
Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Go Beyond UML Use Case and Sequence Diagrams

Reply With Quote





