Exforsys

Online Training

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


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-13-2004, 01:33 PM
Jimbo
Guest
 
Posts: n/a
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2004, 11:14 PM
EventHelix.com
Guest
 
Posts: n/a
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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 On



All times are GMT -4. The time now is 03:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.