Click here to Skip to main content
16,006,749 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unknown Error Message Pin
Vikram A Punathambekar23-Apr-07 6:59
Vikram A Punathambekar23-Apr-07 6:59 
GeneralRe: Unknown Error Message Pin
JMOdom23-Apr-07 7:58
JMOdom23-Apr-07 7:58 
QuestionHow to convert .gif file contains text only to .doc formate in asp.net Pin
attalurisubbu23-Apr-07 4:49
attalurisubbu23-Apr-07 4:49 
AnswerRe: How to convert .gif file contains text only to .doc formate in asp.net Pin
Dave Kreskowiak23-Apr-07 5:56
mveDave Kreskowiak23-Apr-07 5:56 
QuestionHow Making windows Fax Services to send multiple faxes. Pin
Eddymvp23-Apr-07 4:33
Eddymvp23-Apr-07 4:33 
QuestionTrying to understand the Factory Pattern Pin
martin_hughes23-Apr-07 4:29
martin_hughes23-Apr-07 4:29 
AnswerRe: Trying to understand the Factory Pattern Pin
Vikram A Punathambekar23-Apr-07 7:13
Vikram A Punathambekar23-Apr-07 7:13 
AnswerRe: Trying to understand the Factory Pattern Pin
Edmundisme23-Apr-07 11:00
Edmundisme23-Apr-07 11:00 
Like any tool in software development, patterns can be overused. You always want to keep in mind what problem a pattern seeks to solve and make sure this problem exists (or is likely to exist) in your code. Patterns can be used to make your code more flexible, but they can often make your code more complex.

I know of three Factory patterns: Simple Factory, Factory Method, and Abstract Factory.

Simple Factory and Factory Method encapsulate object creation and allow you to decouple the use of a class from its implementation. This allows you to maintain a level of abstraction in your code. For example, you might have code that uses “automobile” objects. The code that uses the “automobile” doesn’t care if it’s a sports car, sedan, minivan or truck. All it cares about is that it is an “automobile”, which means it can be started, driven, and parked.

The key here is that the objects created by the Simple Factory and Factory Method patterns are related - they either implement the same interface or derive from the same base class.

This doesn’t seem to fit what you have going on in your scenario. You have entities such as person, computer, model, and site. These entities aren’t likely to share a direct base class or implement the same interface.

Abstract Factory allows you group together and encapsulate the creation of families of related objects. So, going back to our automobile example, you might have an abstract factory that deals with the creation of Oil and Gasoline objects. The abstract factory would be defined as an interface with two methods:

Interface CarEssentials
{
Gasoline GetGasoline();
Oil GetOil();
}

You would then implement Concrete Factories to return related Gasoline and Oil objects:

Class SporsCarEssentials : CarEssentials
{
Gasoline GetGasoline() { return UltraUnleaded;}
Oil GetOil() {return HighPerformanceOil;}
}

Class SedanEssentials : CarEssentials
{
Gasoline GetGasoline() { return RegularUnleaded;}
Oil GetOil() {return new StandardOil;}
}


Like the Simple Factory and Factory Method patterns, I don’t see Abstract Factory working for you.

Perhaps the reason you are having difficulty figuring out how to apply a Factory pattern to your code is that the Factory patterns aren’t the right tool for the job.

Then again, I could be completely wrong... Smile | :)

Hope this helps!


Ian
AnswerRe: Trying to understand the Factory Pattern Pin
martin_hughes10-May-07 8:41
martin_hughes10-May-07 8:41 
QuestionByte conversion fails Pin
AAKAra23-Apr-07 4:25
AAKAra23-Apr-07 4:25 
AnswerRe: Byte conversion fails Pin
Judah Gabriel Himango23-Apr-07 4:28
sponsorJudah Gabriel Himango23-Apr-07 4:28 
GeneralRe: Byte conversion fails Pin
AAKAra23-Apr-07 4:31
AAKAra23-Apr-07 4:31 
GeneralRe: Byte conversion fails Pin
Judah Gabriel Himango23-Apr-07 4:43
sponsorJudah Gabriel Himango23-Apr-07 4:43 
GeneralRe: Byte conversion fails Pin
AAKAra23-Apr-07 4:50
AAKAra23-Apr-07 4:50 
GeneralRe: Byte conversion fails Pin
AAKAra23-Apr-07 7:55
AAKAra23-Apr-07 7:55 
AnswerRe: Byte conversion fails Pin
Luc Pattyn23-Apr-07 8:29
sitebuilderLuc Pattyn23-Apr-07 8:29 
GeneralRe: Byte conversion fails [modified] Pin
AAKAra23-Apr-07 9:04
AAKAra23-Apr-07 9:04 
GeneralRe: Byte conversion fails Pin
Luc Pattyn23-Apr-07 9:37
sitebuilderLuc Pattyn23-Apr-07 9:37 
QuestionSelecting Row in GridView to show another GridView Pin
junisulaiman23-Apr-07 4:23
junisulaiman23-Apr-07 4:23 
AnswerRe: Selecting Row in GridView to show another GridView Pin
SABhatti23-Apr-07 5:36
SABhatti23-Apr-07 5:36 
GeneralRe: Selecting Row in GridView to show another GridView Pin
junisulaiman2-May-07 7:00
junisulaiman2-May-07 7:00 
GeneralRe: Selecting Row in GridView to show another GridView Pin
SABhatti2-May-07 13:16
SABhatti2-May-07 13:16 
QuestionDigital Persona 4000B Finer Reader Pin
| Muhammad Waqas Butt |23-Apr-07 3:49
professional| Muhammad Waqas Butt |23-Apr-07 3:49 
AnswerRe: Digital Persona 4000B Finer Reader Pin
Judah Gabriel Himango23-Apr-07 4:08
sponsorJudah Gabriel Himango23-Apr-07 4:08 
GeneralRe: Digital Persona 4000B Finer Reader Pin
| Muhammad Waqas Butt |23-Apr-07 4:18
professional| Muhammad Waqas Butt |23-Apr-07 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.