473,383 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Understanding Abstract Factory Pattern

RSH
Hi,

I am a fairly seasoned developer and have recently started looking at
software design patterns. I am starting with the Abstract Factory Pattern
and was wondering if someone could help me understand where I might use this
Pattern. I get the general concept but I am having a hard time converting
that concept into where I might use that in a real world scenerio for a
business application or web development project.

I appreciate the fact that this is a conceptual question, and I appreciate
your time.

Thank you!
Ron
May 15 '07 #1
16 2613
On May 15, 1:21 pm, "RSH" <way_beyond_o...@yahoo.comwrote:
I am a fairly seasoned developer and have recently started looking at
software design patterns. I am starting with the Abstract Factory Pattern
and was wondering if someone could help me understand where I might use this
Pattern. I get the general concept but I am having a hard time converting
that concept into where I might use that in a real world scenerio for a
business application or web development project.
Suppose you had encapsulated your data access into an interface, and
had implemented that interface for Oracle, SQL Server etc.

The abstract factory pattern would give you a central factory to call
which would in turn call the appropriate concrete factory depending on
configuration.

At least, that's the way I understand it.

Jon

May 15 '07 #2
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
Suppose you had encapsulated your data access into an interface, and
had implemented that interface for Oracle, SQL Server etc.

The abstract factory pattern would give you a central factory to call
which would in turn call the appropriate concrete factory depending on
configuration.

At least, that's the way I understand it.
Yes indeed.

What happens when you add a provider that's not part of the "standard" .NET
Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try to
run it on a machine which doesn't have the MySQL .NET native data provider,
won't your app fall over due to missing references etc...?
--
http://www.markrae.net

May 15 '07 #3
On May 15, 1:49 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
At least, that's the way I understand it.

Yes indeed.

What happens when you add a provider that's not part of the "standard" .NET
Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try to
run it on a machine which doesn't have the MySQL .NET native data provider,
won't your app fall over due to missing references etc...?
I believe the references will only be fetched when they're first
actively used. That's what I'd hope, anyway - I haven't actually tried
it :)

I'm sure with suitable levels of indirection it should be okay.

Jon

May 15 '07 #4
RSH
I almost understand that.

Are there any tutorials you know of that illustrate this concept?

Thanks,
Ron
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
On May 15, 1:21 pm, "RSH" <way_beyond_o...@yahoo.comwrote:
>I am a fairly seasoned developer and have recently started looking at
software design patterns. I am starting with the Abstract Factory
Pattern
and was wondering if someone could help me understand where I might use
this
Pattern. I get the general concept but I am having a hard time
converting
that concept into where I might use that in a real world scenerio for a
business application or web development project.

Suppose you had encapsulated your data access into an interface, and
had implemented that interface for Oracle, SQL Server etc.

The abstract factory pattern would give you a central factory to call
which would in turn call the appropriate concrete factory depending on
configuration.

At least, that's the way I understand it.

Jon

May 15 '07 #5
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@h2g2000hsg.googlegrou ps.com...
I believe the references will only be fetched when they're first
actively used. That's what I'd hope, anyway - I haven't actually tried
it :)
Hmm - I'm sure that's correct, although I've never tried it either!
I'm sure with suitable levels of indirection it should be okay.
All my work tends to be targeted at one specific RDBMS - I've never been
asked to write anything which supported multiple providers...

Therefore, I have four quite separate DALs - SqlClient, OleDb, MySql and
most recently SqlCe...

I guess an abstract factory pattern might be more efficient as far as
development goes, but I'm not sure there's much point in a client receiving
a bespoke app with redundant code...
--
http://www.markrae.net

May 15 '07 #6
Hi,

Buy the Design Pattern book :
http://www.amazon.com/Design-Pattern...9238351&sr=8-1

There you will find a good example of how to use each pattern based on a
Text Editor.

IIRC the example there is to how to handle different UI libraries without
modifying the code, let's say you want a program to run on MacOS, Win,
Linux, etc. You know that each of these system implement the same set of
controls (TextBox, CheckBox, ListBox,etc)
in such a way that you can declare an anbstract class (or inteface).

Your code does not need to know which one especifically is being used. It
just request an instance of ITextbox and the factory returns an instance of
it. Depending of what library is in used you get a instance of a Textbox of
the running system(MacOS, Win, Linux).

Take also a look at wikipedia, they have good articles explaining the
differents patterns.
"RSH" <wa*************@yahoo.comwrote in message
news:eB**************@TK2MSFTNGP03.phx.gbl...
Hi,

I am a fairly seasoned developer and have recently started looking at
software design patterns. I am starting with the Abstract Factory Pattern
and was wondering if someone could help me understand where I might use
this Pattern. I get the general concept but I am having a hard time
converting that concept into where I might use that in a real world
scenerio for a business application or web development project.

I appreciate the fact that this is a conceptual question, and I appreciate
your time.

Thank you!
Ron

May 15 '07 #7
Hi,

"RSH" <wa*************@yahoo.comwrote in message
news:eS**************@TK2MSFTNGP03.phx.gbl...
>I almost understand that.

Are there any tutorials you know of that illustrate this concept?
The original book (see my other email) about Design pattern has a very
extense example using a Text Editor.

Also google for the desired pattern and you will get several examples
May 15 '07 #8
Hi,

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
>Suppose you had encapsulated your data access into an interface, and
had implemented that interface for Oracle, SQL Server etc.

The abstract factory pattern would give you a central factory to call
which would in turn call the appropriate concrete factory depending on
configuration.

At least, that's the way I understand it.

Yes indeed.

What happens when you add a provider that's not part of the "standard"
.NET Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try to
run it on a machine which doesn't have the MySQL .NET native data
provider, won't your app fall over due to missing references etc...?
Yes, it will fail at runtime. It will fail when you first try to use it
May 15 '07 #9
Hi,

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@h2g2000hsg.googlegrou ps.com...
On May 15, 1:49 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
At least, that's the way I understand it.

Yes indeed.

What happens when you add a provider that's not part of the "standard"
.NET
Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try to
run it on a machine which doesn't have the MySQL .NET native data
provider,
won't your app fall over due to missing references etc...?

I believe the references will only be fetched when they're first
actively used. That's what I'd hope, anyway - I haven't actually tried
it :)
You are correct, I have one app that use VFP and when I install it on a
machine without the OLEDB provider I get the error when I first try to use
the provider.
May 15 '07 #10
RSH
So correct me if Im wrong....

The Abstract Factory is really like a runtime switch that instntiates the
appropriate class based on the conditions at run time. It encapsulates not
only the classes but the logic associated with selecting the appropriate
class to create the object.

The use of an interface further promotes loose coupling between the factory
and the underlying classes.

I can see the usefullness in this for sure.

Ron
"RSH" <wa*************@yahoo.comwrote in message
news:eB**************@TK2MSFTNGP03.phx.gbl...
Hi,

I am a fairly seasoned developer and have recently started looking at
software design patterns. I am starting with the Abstract Factory Pattern
and was wondering if someone could help me understand where I might use
this Pattern. I get the general concept but I am having a hard time
converting that concept into where I might use that in a real world
scenerio for a business application or web development project.

I appreciate the fact that this is a conceptual question, and I appreciate
your time.

Thank you!
Ron

May 15 '07 #11
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Od**************@TK2MSFTNGP04.phx.gbl...
>What happens when you add a provider that's not part of the "standard"
.NET Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try to
run it on a machine which doesn't have the MySQL .NET native data
provider, won't your app fall over due to missing references etc...?

Yes, it will fail at runtime. It will fail when you first try to use it
Just to clarify, does that mean the app will fail the first time it tries to
use any part of the DAL...?

E.g. if your DAL supports both SqlClient and SqlCe, can you still use the
SqlClient "bits" even if the SqlCe runtime isn't installed...?
--
http://www.markrae.net

May 15 '07 #12
Hi,

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Od**************@TK2MSFTNGP04.phx.gbl...
>>What happens when you add a provider that's not part of the "standard"
.NET Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try
to run it on a machine which doesn't have the MySQL .NET native data
provider, won't your app fall over due to missing references etc...?

Yes, it will fail at runtime. It will fail when you first try to use it

Just to clarify, does that mean the app will fail the first time it tries
to use any part of the DAL...?
The application will fail when you first try to use any feature not
currently present in the machine.

In my example if I have no registered the OleDB provider for VFP
(vfpoledb.dll) the application throw an exception when I try to create it
:OleDbConnection conn = new OleDbConnection("......");
May 15 '07 #13
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:ed*************@TK2MSFTNGP03.phx.gbl...
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote
in message news:Od**************@TK2MSFTNGP04.phx.gbl...
>>>What happens when you add a provider that's not part of the "standard"
.NET Framework, e.g. MySQL or SqlCe...?

If your DAL factory includes SqlClient, Oracle *and* MySQL and you try
to run it on a machine which doesn't have the MySQL .NET native data
provider, won't your app fall over due to missing references etc...?

Yes, it will fail at runtime. It will fail when you first try to use it

Just to clarify, does that mean the app will fail the first time it tries
to use any part of the DAL...?

The application will fail when you first try to use any feature not
currently present in the machine.

In my example if I have no registered the OleDB provider for VFP
(vfpoledb.dll) the application throw an exception when I try to create it
:OleDbConnection conn = new OleDbConnection("......");
OK - thanks very much...
--
http://www.markrae.net

May 15 '07 #14
Mark Rae <ma**@markNOSPAMrae.netwrote:
I'm sure with suitable levels of indirection it should be okay.

All my work tends to be targeted at one specific RDBMS - I've never been
asked to write anything which supported multiple providers...
I've only done one project which really needed it, but then we used
Hibernate so we didn't have our own abstract factory anyway. We only
needed two types of servers for production - Oracle and SQL server -
but we developed and ran unit tests against HSQLDB as well, which was
blindingly fast and therefore great for unit tests.

It's certainly interesting writing multi-backend solutions.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 15 '07 #15


There is a difference between the Simple Factory Pattern
and the Abstract Factory Pattern.

I'm very good with the Simple (of course, its simple) pattern.

The Abstract one illudes you for a while, but you can get it.

http://www.dofactory.com/Patterns/PatternAbstract.aspx
but the example is a not so crystal clear.

I have a java book at home ... that gave me an example that I could finally
figure it out.
Let me know if you're interested in the ISBN.

"RSH" <wa*************@yahoo.comwrote in message
news:Om**************@TK2MSFTNGP06.phx.gbl...
So correct me if Im wrong....

The Abstract Factory is really like a runtime switch that instntiates the
appropriate class based on the conditions at run time. It encapsulates
not
only the classes but the logic associated with selecting the appropriate
class to create the object.

The use of an interface further promotes loose coupling between the
factory
and the underlying classes.

I can see the usefullness in this for sure.

Ron
"RSH" <wa*************@yahoo.comwrote in message
news:eB**************@TK2MSFTNGP03.phx.gbl...
Hi,

I am a fairly seasoned developer and have recently started looking at
software design patterns. I am starting with the Abstract Factory
Pattern
and was wondering if someone could help me understand where I might use
this Pattern. I get the general concept but I am having a hard time
converting that concept into where I might use that in a real world
scenerio for a business application or web development project.

I appreciate the fact that this is a conceptual question, and I
appreciate
your time.

Thank you!
Ron


May 15 '07 #16
I've recently posted to my blog regarding this pattern, take a look
there are a couple of good examples on this topic:
http://ehsanbraindump.blogspot.com/2...actory_21.html

I'm also going to post another post there in the next few days that will
complete the discussion. Be sure to return in a few days.
*** Sent via Developersdex http://www.developersdex.com ***
May 24 '07 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
4
by: max | last post by:
Hello, I analyze this design pattern for a long time but I do not understand how this pattern work and what the purpose is? (I looked a this site...
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
2
by: Julia | last post by:
Hi, I have an application composed from layers like the following A --B ---C A is the top layer C uses an Abstract Factory to Create Concrete classes
3
by: Christer | last post by:
Hi all! We're creating an administration for a web application. This includes severeal aspx pages. Our key entity in the web application is "Profile", which can have a certain type. Based on...
2
by: Duy Lam | last post by:
Hi everyone, Sorry, I don't know what group to post this problem, I think may be this group is suitable. I'm styduing DAO (Data Access Object) pattern in this link...
3
by: suresh_rai | last post by:
Hello I am hoping someone can give me very needed help. I am wanting some C+ + code for 'C++ Abstract Factory'. I need code to be free. I am been learning Design patterns. I found some code on...
4
by: C# | last post by:
http://www.questpond.com/FreeDesign1.htm I was going through the above videos. Can i conclude Abstract factory patterns are extensions of factory patterns. I have made the conclusion after...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.