views:

313

answers:

2

Hi

I got an exam in two days and one of the questions is how JDBC uses the abstract factory. I myself is not so skilled with design patterns, so maybe somebody here had the answer.

I was thinking that maybe, DriverManager.getConnection(url) is an example of abstract factory, but am not sure. Or is it a factory method?

+1  A: 

Obviously, the purpose of the question is for you to be able to understand the Abstract Factory Pattern, and how it is used. The best way for you to find this out is to read about it; here is the wikipedia article on the Abstract Factory Pattern.

http://en.wikipedia.org/wiki/Abstract_factory_pattern

McWafflestix
I find it really hard learning patterns. Getting feedback from others might be what I need to understand them.Anyway, I was thinking that DriverManager is the abstract factory and Connection is the abstract product. When a url is given to the abstract factory(DriverManager) it decides what kind of factory to use like WinDriverFactory, DerbyDriverFactory etc. and call one of those to get the Connection.
bobjink
@bobjink: yes, I think your assessment is correct; sounds like you have a better grasp on patterns than you may think! :-)
McWafflestix
Thx, just what I wanted to hear!Still not 100% i get it. DP's used in program does not look like the ones in the books. Fx it confuses me that the abstract factory takes a String/Url and not a factory like in the example.Anyway thx for your coment :)
bobjink
@bobjink: yes, that's correct; usage in real life doesn't look like the books. This is because the design patterns are just that, patterns; they describe a certain ideal, but not a precise form. Much like the sweater your grandmother made for you (say) doesn't look precisely like the pattern she used; maybe she used a different yarn, maybe she made the sleeves too long (like mine did), maybe she forgot to add a collar; the specifics are dependent upon her implementation, but the pattern that she used was still there. Design patterns are all about being able to "see the forest for the trees".
McWafflestix
A: 

Your exam is probably going to be about Design Patters, so I recommend that you go ahead and study design patters in details. A good book for this is Objects, Components , Models and Patterns with ISBN 9783540698234. Please make sure to study all the patterns in detail since is mostly theory. If you need examples go to wikipedia or other sources those are very helpful to understand the theory. I am sure you will get the point if someone here points you out the answer, but what the teacher is looking is for you to understand the concept.

If this is an exam about JDBC instead, then getting the answer from here will not be a big problem. I hope you do well in your exam.

Geo