Hi If you want loose coupling and extensibilty in the future - go for the Factory pattern. It comes highly recommended.
Hermod -----Opprinnelig melding----- Fra: Anye M. Sellers [mailto:[EMAIL PROTECTED]] Sendt: 4. mai 2002 03:44 Til: JDJList Emne: [jdjlist] OT: Design patterns: Abstract factory vs. factory method/template method Hi folks, This is aimed toward the architect types in the audience.... I'm working on an app that needs to support both Oracle and SQL Server and that needs different implementations of the data access classes as a result. I've been studying design patterns and I've found a couple similar patterns that seem ideal but I am having trouble getting a feel for when you would use each one. One is the abstract factory, which returns to the client either the SQL or Oracle version of a data object that implements the custom IDataAccess interface. It has a couple extra steps in there: client --> Factory Maker --> Factory --> Object as interface --> call methods on interface like so: DBObjFactory dbfact = new DBObjectFactory(); IDBObj objFact; IDBAccess objDA; objFact = dbfact.GetDataObjectFactory(dbtype); objDA = objFact.GetDBObject(); objDA.DoStuff(); The other is the Template method pattern (in fact the book I'm reading used my case study as its example!) where I would define an abstract class that defines the public method which is called by the client and that has abstract methods for the db specific stuff which are implemented by child classes (one for each DB). In this scenario, it seems that the flow is client --> instantiate child object and assign to parent reference --> call methods on parent reference, the code from child is used. like so: DBAccess dba; switch(intDBtype){ case 0: // oracle dba = new OraDBAccess(); // inherits DBAccess case 1: // Sql dba = new SqlDBAccess(); //inherits DBAccess } dba.DoStuff(); (If I'm misunderstanding any of these, please let me know...) It looks like abstract factory has more overhead in terms of objects created, but it seems like it might favor composition over inheritance and would allow me to use the same factory maker for other types of factories that I may need. Do any of you folks know the advantages and disadvantages of each method and which would be better? Thanks in advance, Anye __________________________________________________ Do You Yahoo!? Yahoo! Health - your guide to health and wellness http://health.yahoo.com To change your membership options, refer to: http://www.sys-con.com/java/list.cfm * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This email with attachments is solely for the use of the individual or entity to whom it is addressed. Please also be aware that DnB cannot accept any payment orders or other legally binding correspondence with customers as a part of an email. This email message has been virus checked by the virus programs used in the DnB Group. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * To change your membership options, refer to: http://www.sys-con.com/java/list.cfm
