The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

abstract factories

Posted by Chin Loong on January 23, 2002 at 6:03 AM

this is exactly how it was done in my previous company.

i was just beginning to learn java at the time, so it was really a hell trying to catch up. anyway, the structure is something like this : (not really sure coz i can't really remember, and i didn't really catch up at this part too... :p too busy learning servlets and jsp at that time.)


public class DataManager
{
// initializes database driver if not already initialized
// obtains connection and etc.
}

i.e. if we were supposed to access data from table [customer]


public abstract class AbstractCustomer extends DataManager
{
public static Customer findByPrimaryKey(int id);
// etc etc
}

public class DB2CustomerDM extends AbstractCustomer // for DB2
{
public static Customer findByPrimaryKey(int id)
{
// obtains connection and sends SELECT query to db2
}
}

public class MYSQLCustomerDM extends AbstractCustomer // mySQL
{
public static Customer findByPrimaryKey(int id)
{
// obtains connection and sends SELECT query to mysql
}
}

during execution :

public void someMethod(int id)
{
String dbFactory = // read from properties file that might contain
// values like Customer=com.company.database.MYSQLCustomerDB
// and subsitute the value into the string
AbstractCustomer aCustomer=(AbstractCustomer)Class.forName(dbFactory).newInstance();
Customer customer=aCustomer.findByPrimaryKey(id);
...
...
}

so there'll be a properties file or rather, an LDAP server that matches the list of database tables with the correct factory.

or something like that.. this is from what i barely remembered during my 3-month internship there. massive learning at that time.. didn't get to catch up on this concept. caught up on jsp and servlets though :p

anyway, they got some kind of horizontal framework that they later extend into vertical framework for the community portal products that they make. marketing stuff :p



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us