Factory class

Hi
I could not understand the concept of factory classes and why they are being used in many j2ee design patterns. probably this is a design question but not sure. please help me out.

Hi
I could not understand the concept of factory classes
and why they are being used in many j2ee design
patterns. probably this is a design question but not
sure. please help me out.It tends to be about hiding concrete implementation classes behind interfaces so that, for example, a different implementation can be substituted transparently.
For example, using this technique, the application program doesn't need to know if an object is implemented locally or remotely.
The JDBC is an example familiar to most. You never instantiate a Connection, Statement, ResultSet yourself. All you see is interfaces. The concrete classes behind them depend which database you're using and are hidden away in the driver libraries. The DriverManager is the factory class in this case.
You can have one central routine which searches the libraries supplied for candidate factory classes and asks each in turn if it can provide an implementation of the interface you want.

Similar Messages

  • Unable to load your custom module provider's module-factory-class

    I am having a problem while I deploy my application. it gives me following error:
    Unable to load your custom module provider's module-factory-class com.bea.p13n.descriptor.module.ConfigModuleFactory
    Dont know how to resolve it. the class is in p13n_system.jar file, I have added that jar as a library in deployment but still it shows the same error.
    Added it in classpath as well but same error. (Dont know exactly how to add in class path, i have added just in "Start Server" tab's classpath)
    Any help will be greatly appreciated

    Below link might be helpful.
    http://kr.forums.oracle.com/forums/thread.jspa?threadID=1049509&tstart=0
    Regards,
    Anandraj
    http://weblogic-wonders.com/

  • Why use Factory classes

    Why do we use Factory classes such BorderFactory, to get an instance of Border class, why cant we directly create an object of such classes like we do with regular concrete classes

    Why do we use Factory classes such BorderFactory, to
    get an instance of Border class, why cant we directly
    create an object of such classes like we do with
    regular concrete classesFactory methods (I mean static create methods here) have two advantages.
    First, the library designer doesn't have to expose concrete classes to the outside world, just interfaces. This adds flexibility.
    Second, the library designer is free to make object creations more flexible. The create method may take parameters that doesn't exactly correspond to a constructor of one specific class.

  • Initializing Factory class with Digital Signature

    Hi All,
    I am trying to Initialize the Factory class using digital signature. These are the steps I fallowed.
    1. Created a Java application "Application1" in Jdeveloper.
    2. Copied config, ext, lib folder from the Design console directory to the Application1/Project1 folder.
    3. added the lib and ext jars to the project properties.
    4. Modified the run/debug profile in the project properties to point to the xlconfig file in config folder.
    5. added the "-DXL.HomeDir=. -Djava.security.auth.login.config=config\authwl.conf" in the java options.
    Java code:
    public class SignatureLogin {
    public static void main(String[] args) throws Exception {
    Properties jndi =
    ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer").getAllSettings();
    tcSignatureMessage signedMsg = tcCryptoUtil.sign("xelsysadm", "PrivateKey");
    tcUtilityFactory factory = new tcUtilityFactory(jndi, signedMsg);
    tcUserOperationsIntf usrIntf = (tcUserOperationsIntf)factory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
    System.out.println("signature login complete");
    // Do something with usrIntf here
    Map filter = new HashMap();
    filter.put("Users.Key", "7464");
    tcResultSet rSet = usrIntf.findAllUsers(filter);
    rSet.goToRow(0);
    System.out.println(rSet.toString());
    factory.close();
    System.out.println("logout complete");
    System.exit(0);
    Then ran the java class. I am able to get the connection but when I am using findAllUsers(map) method to search the usr table I am get a nullpointer exception.
    Exception in thread "main" java.lang.NullPointerException
         at Thor.API.Operations.tcUserOperationsClient.findAllUsers(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at Thor.API.Base.SecurityInvocationHandler$1.run(Unknown Source)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(Unknown Source)
         at weblogic.security.Security.runAs(Security.java:41)
         at Thor.API.Security.LoginHandler.weblogicLoginSession.runAs(Unknown Source)
         at Thor.API.Base.SecurityInvocationHandler.invoke(Unknown Source)
         at $Proxy0.findAllUsers(Unknown Source)
         at com.ssi.utils.custom.code.SignatureLogin.main(SignatureLogin.java:26)
    I need some help to fix this.
    Thanks

    Hi,
    Were you able to resolve the issue as I am facing same issue.
    I have a custom application deployed on same weblogic managed server where OIM is installed but when I try to find user in OIM it gives me null pointer exception.
    I have even checked the username with which connection is established using ioUtilityFactory.getUserName() and it gives me the correct user.
    Thanks
    Edited by: user1105482 on 26-Apr-2011 04:38

  • Abap Objects-Factory classes

    Hi All,
    We are thinking of developing some factory classes in ABAP.Cud u suggest some ? May be analogous to those factory classes in other programming languages also.

    Hi Hema,
    I thing you can go for a Validation Factory that has lots and lots of validation functions like basic validations ( e.g. decimal number, email address etc.) and business validations ( that contains templets for validations which could be overwritten for a specific application).
    This is actually a very usefull functionality that is usually written again and again for all development projects.
    Best regards,
    Guru.
    PS : Don't forget to give points

  • Unusual use of interface defining static factory class with getInstance

    This question is prompted by a recent New to Java forum question ask about the differences between Interfaces and Abstract classes. Of course one of the standard things mentioned is that interfaces cannot actually implement a method.
    One of my past clients, one of the 500 group, uses interfaces as class factories. The interface defines a pubic static class with a public static method, getInstance, that is called to generate instances of a class that implements the interface.
    This architecture was very object-oriented, made good use of polymorphism and worked very well. But I haven't seen this architecture used anywhere else and it seemed a little convoluted.
    Here is a 'pseudo' version of the basic interface template and use
    -- interface that defines public static factory class and getInstance method
    public interface abc {
        public static class FactoryClass
            public static abc getInstance ()
                return (abc) FactoryGenerator(new abcImpl(), abc.class);
    -- call of interface factory to create an instance
    abc myABC = abc.Factory.getInstance();1. Each main functional area ('abc' in the above) has its own interface factory
    2. Each main functional area has its own implementation class for that interface
    3. There is one generator (FactoryGenerator) that uses the interface class ('abc.class') to determine which implementation class to instantiate and return. The generator class can be configured at startup to control the actual class to return for any given interface.
    I should mention that the people that designed this entire architecture were not novices. They wrote some very sophisticated multi-threaded code that rarely had problems, was high performance and was easy to extend to add new functionality (interfaces and implementing classes) - pretty much plug-n-play with few, if any, side-effects that affected existing modules.
    Is this a best-practices method of designing factory classes and methods? Please provide any comments about the use of an architecture like this.

    Thanks for the feedback.
    >
    I don't see how 'the generator class can be configured at startup to control the actual class to return for any given interface' can possibly be true given this pseudo-code.
    >
    I can see why that isn't clear just from what is posted.
    The way it was explained to me at the time is that the interface uses standard naming conventions and acts like a template to make it easy to clone for new modules: just change 'abc' to 'def' in three places and write a new 'defImpl' class that extends the interface and the new interface and class can just 'plug in' to the framework.
    The new 'defImpl' class established the baseline functionality that must be supported. This line
    return (abc) FactoryGenerator(new abcImpl(), abc.class);uses the initial version of the new class that was defined, 'abcImpl()', when calling the FactoryGenerator and it acted as a 'minimum version supported'. The generator class could use configuration information, if provided, to provide a newer class version that would extend this default class. Their reasoning was that this allowed the framework to use multiple versions of the class as needed when bugs got fixed or new functionality was introduced.
    So the initial objects would be an interface 'abc' and a class 'abcImpl'. Then the next version (bug fixes or enhancements) would be introduced by creating a new class, perhaps 'abcImpl_version2'. A configuration parameter could be passed giving 'abcImpl' as the base class to expect in the FactoryGenerator call and the generator would actually create an instance of 'abcImpl_version2' or any other class that extended 'abcImpl'.
    It certainly go the job done. You could use multiple versions of the class for different environments as you worked new functionality from DEV, TEST, QA and PRODUCTION environments without changing the basic framework.
    I've never seen any Java 'pattern' that looks like that or any pattern where an interface contained a class. It seemed really convoluted to me and seems like the 'versioning' aspect of it could have been accomplished in a more straightforward manner.
    Thanks for the feedback. If you wouldn't mind expanding a bit on one comment you made then I will mark this ANSWERED and put it to rest.
    >
    I don't mind interfaces containing classes per se when necessary
    >
    I have never seen this except at this one site. Would you relate any info about where you have seen or used this or when it might be necessary?

  • Connection Factory class for Distributed Transaction?

    Definition of Managed Datasources goes like this at URL: http://download.oracle.com/docs/cd/B31017_01/web.1013/b28958/datasrc.htm#CHDDADCE
    Managed data sources are managed by OC4J. This means that OC4J provides critical system infrastructure such as global transaction management, connection pooling, and error handling.
    In the same document, I could also see a section for configuring Connection Pool, that uses 'factory-class' as 'oracle.jdbc.pool.OracleDataSource' as shown below:
    <connection-pool name="myConnectionPool">
    <connection-factory
    factory-class="oracle.jdbc.pool.OracleDataSource"
    user="scott"
    password="tiger"
    This configuration has worked well for my web application where I was using a single instance of Oracle database. In a new application I've to use two separate instance of Oracle databases and there is a need of distributed transaction.
    I know, I've to create two separate datasources for the two separate Oracle instances.
    My question is: Since now my transaction will be distributed in nature, do I need to use any other factory-class for configuring XA aware Datasources on OC4J? Or whether the same factory-class (oracle.jdbc.pool.OracleDataSource) will work even for distributed transactions?

    Here is the link for using Oracle RAC with WLS
    http://e-docs.bea.com/wls/docs81/jdbc/oracle_rac.html

  • Binding Factory Class

    Dear people,
    I am relatively new in Oracle JDeveloper ( using it last 3 months ) and during my last task I am facing a problem to which i can not find the solution...
    I am trying to set up a factory class from which i will get a Dynamic Table Binding depending on the given data. The problem I am facing has to do with getting a NullPointerException whenever I am trying to use my given panelBinding. Although i search numerous questions and answers in the forum and read a number of different examples given by the Aces I cant find a solution to this. Here is my code...
    *public class BindingFactory  {*
    *public BindingFactory() {*
    public   JUPanelBinding panelBinding = new JUPanelBinding("BindingFactoryPageDef");
    public  JUTableBinding create  (String objName,
    String attributes,
    String[] attributesNeeded
    *) throws Exception {*
    JTable myTable = new JTable();
    */*Locating and Loading AppModule*/*
    ApplicationModule am = Configuration.createRootApplicationModule("model.EmpRegistryAppModule","EmpRegistryAppModuleLocal");++
    panelBinding.setApplicationModule(am);
    */* Creating VO from Data given in method call */*
    ViewObject myVO  = am.createViewObjectFromQueryStmt(objName, "SELECT " + attributes + " FROM " + objName );
    */*Executing the VO Query to produce the Rowset*/*
    myVO.executeQuery();
    */*Creating the rowSet iterator */*
    RowSetIterator rsi = myVO.createRowSetIterator("DynamicIterator");
    JUMetaObjectManager.setErrorHandler(new JUErrorHandlerDlg());
    JUMetaObjectManager mgr = JUMetaObjectManager.getJUMom();
    mgr.setJClientDefFactory(null);
    BindingContext binding = new BindingContext();
    binding.put(DataControlFactory.APP_PARAM_ENV_INFO, new JUEnvInfoProvider());
    binding.setLocaleContext(new DefLocaleContext(null));
    HashMap map = new HashMap(4);
    map.put(DataControlFactory.APP_PARAMS_BINDING_CONTEXT, binding);
    mgr.loadCpx("view.DataBindings2.cpx" , map);
    */* This is where Null Pointer is coming from...*/*
    ---->     DCDataControl app = panelBinding.getBindingContext().findDataControl("EmpRegistryAppModuleDataControl");
    app.setClientApp(DCDataControl.JCLIENT);
    JUIteratorBinding itBinding = new JUIteratorBinding(app, rsi);
    myTable.setModel((TableModel)panelBinding.bindUIControl(objName+"ViewObject2",myTable));
    JUTableBinding tb = new JUTableBinding(myTable, itBinding ,attributesNeeded);
    return tb;
    Any Ideas?
    Thanks in advance for your time and help.
    Regards,
    Pelopidas
    Edited by: Zouridakis Pelopidas on Dec 23, 2010 6:22 AM
    Edited by: Zouridakis Pelopidas on Dec 28, 2010 3:11 AM
    Edited by: Zouridakis Pelopidas on Dec 28, 2010 3:26 AM
    Edited by: Zouridakis Pelopidas on Dec 29, 2010 1:41 AM

    Hi all,
    Since I finally managed to set this up properly, i am posting my code here in order to share with everyone, since i couldnt find many similar examples!
    It works fine in Oracle JDev 10.1.3.5.
    To sum up, this is a factory class which receive the name of your entity object and dynamically creates a binded table ready for use.
    import java.util.HashMap;
    import javax.swing.JTable;
    import javax.swing.table.TableModel;
    import model.Employees1DefImpl;
    import oracle.adf.model.BindingContext;
    import oracle.adf.model.DataControlFactory;
    import oracle.adf.model.binding.DCDataControl;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.ViewObject;
    import oracle.jbo.common.DefLocaleContext;
    import oracle.jbo.server.EntityDefImpl;
    import oracle.jbo.uicli.binding.JUUtil;
    import oracle.jbo.uicli.controls.JUErrorHandlerDlg;
    import oracle.jbo.uicli.jui.JUEnvInfoProvider;
    import oracle.jbo.uicli.jui.JUPanelBinding;
    import oracle.jbo.uicli.jui.JUTableBinding;
    import oracle.jbo.uicli.mom.JUMetaObjectManager;
    *public class BindingFactory  {*
    *public BindingFactory() {*
    public JUPanelBinding panelBinding = new JUPanelBinding("BindingFactoryPageDef");
    public  JTable createDynamicBindedTable   (String objName,
    String[] attributesNeeded
    *) throws Exception {*
    JTable myTable = new JTable();
    JUMetaObjectManager.setErrorHandler(new JUErrorHandlerDlg());
    JUMetaObjectManager mgr = JUMetaObjectManager.getJUMom();
    mgr.setJClientDefFactory(null);
    BindingContext binding = new BindingContext();
    binding.put(DataControlFactory.APP_PARAM_ENV_INFO, new JUEnvInfoProvider());
    binding.setLocaleContext(new DefLocaleContext(null));
    HashMap map = new HashMap(4);
    map.put(DataControlFactory.APP_PARAMS_BINDING_CONTEXT, binding);
    mgr.loadCpx("view.DataBindings2.cpx" , map);
    DCDataControl app = binding.findDataControl("EmpRegistryAppModuleDataControl");
    */*Locating and Loading AppModule*/*
    ApplicationModule am = (ApplicationModule)app.getDataProvider();
    panelBinding.setApplicationModule(am);
    */* Creating VO from Data given in method call */*
    ViewObject myVO  = am.createViewObjectOnEntity(objName+"Success", "model."+objName );
    */*Executing the VO Query to produce the Rowset*/*
    myVO.executeQuery();
    app.setClientApp(DCDataControl.JCLIENT);
    TableModel tableModel = JUTableBinding.createAttributeListBinding( panelBinding, myTable,
    objName+"Success", null, objName + "Iter", attributesNeeded );
    myTable.setModel(tableModel);
    return myTable;
    *public JUPanelBinding getPanelBinding() {*
    return panelBinding;
    *public void setBindingContext(BindingContext bindCtx) {*
    *if (panelBinding.getPanel() == null) {*
    panelBinding = panelBinding.setup(bindCtx, this);
    panelBinding.refreshControl();
    *try {*                  
    registerProjectGlobalVariables(bindCtx);
    panelBinding.refreshControl();
    *} catch (Exception ex) {*
    panelBinding.reportException(ex);
    *private void registerProjectGlobalVariables(BindingContext bindCtx) {*
    JUUtil.registerNavigationBarInterface(panelBinding, bindCtx);
    *private void unRegisterProjectGlobalVariables(BindingContext bindCtx) {*
    JUUtil.unRegisterNavigationBarInterface(panelBinding, bindCtx);
    *public void bindNestedContainer(JUPanelBinding ctr) {*
    *if (panelBinding.getPanel() == null) {*
    ctr.setPanel(this);
    panelBinding.release(DCDataControl.REL_VIEW_REFS);
    panelBinding = ctr;
    registerProjectGlobalVariables(panelBinding.getBindingContext());
    *try {*
    *} catch (Exception ex) {*
    ex.printStackTrace();
    ctr.reportException(ex);
    Thanks for your time and help,
    Pelopidas

  • Proper object oriented design for factory class

    I have a factory class (UserFactory) it is capable of creating two types of classes (Customer and Employee) that extend User. User is an abstract class.
    At present any class could create a Customer of an Employee.
    How do I restrict access to the constructors of Customer and Employee only to UserFactory?
    I don't want to make both of these classes interfaces (in which case I could just have UserFactory implement both of them).
    Here is an example of how they are set up at present:
    public abstract class User {
    public class Customer extends User{
    public Customer{
    public class Employee extends User {
    public Employee {
    public class UserFactory ???? {
    private static UserFactory c_userFactory = null;
    private UserFactory (){
    public UserFactory getInstance(){
    //private clone method too
    public Customer createCustomer(){
    public Employee createEmployee(){
    Oh and I don't want to create two separate factory classes for Employee and Customer. In C++ there is a concept of friend classes that would have worked nicely in this case.
    Thanks for any and all suggestions,
    Tim

    So correct me if I'm wrong but your suggestion would be something along the lines of:
    public abstract class User {
    public class Customer extends User{
    protected Customer(){
    public class Employee extends User {
    protected Employee (){
    public class UserFactory ???? {
    private static UserFactory c_userFactory = null;
    private UserFactory (){
    public UserFactory getInstance(){
    //private clone method too
    public Customer createCustomer(){
    public Employee createEmployee(){
    public class AccessForCustomer extends Customer {
    public class AccessForEmployee extends Employee {
    Is the above about what you were talking about? I haven't used inner classes before, so I'm a bit curious. Does this mean no class other than UserFactory or derivatives thereof can access the two classes AccessForCustomer and AccessForEmployee?
    Thanks,
    Tim

  • SAAJ 1.2 factory class for Weblogic 9 ?

    Whats the name of the SAAJ factory class to use in WLS 9.0
    to use SAAJ 1.2 functionality ?
    I tried
    System.setProperty("javax.xml.soap.SOAPFactory",
    "com.bea.saaj.SOAPFactoryImpl");
    but I keep getting a class not found exception. When I use the
    default factory I get a method not supported.
    Any ideas ?
    /s

    How about
    System.setProperty("javax.xml.soap.MessageFactory", "weblogic.xml.saaj.MessageFactoryImpl");
    System.setProperty("javax.xml.soap.SOAPFactory", "weblogic.xml.saaj.SOAPFactoryImpl");
    Jong

  • Factory class and static members

    I don't understand very well why sometimes you can find a factory class (for example for the xml parsers). What's its aim?
    And why sometuimes, instead of a constructor, some classes have only static methods that returns a reference to that object?
    Anyone can tell me?
    Thanks

    Static memebers can be used in places where instances of its enclosing class is not neccesary.Only a method is required to be executed. Let me tell you with an example,
    class ConnectionPool {
    public static giveConnection(int index) {
    In the above example, our objective is to use only the method public static giveConnection(int index) {} , and not any of the other attributes of this class. You have 2 ways to use this method : One is, you can instantiate ConnectionPool p = new ConnectionPool(); . Second is , just use ConnectionPool.giveConnection(2);
    The first solution may create instance and obstruct your performance. Seond one does not do that. All invokers of this method do not instantiate and occupy space.
    Usually, factory classes have static members. Because these classes are used as a supporting processing factory. Theses members can be considered as utility methods. Hence static property will better suit for them. This answer will also tell you that the use of constructors here is not neccessary.
    Hope this has helped you.
    Rajesh

  • Factory-class in data-sources.xml managed-data-source

    OracleAS_1\j2ee\home\config has
    data-sources.xml
    Using managed-data-source.
    For connection-pool, connection-factory factory-class If I use OracleDriver instead of OracleDataSource, what difference would it have? In terms of performance?
    Thanks.

    Oops, a case issue...
    class="oracle.jdbc.pool.Oracle[b]OCIConnectionPool"

  • Java Factory Classes

    What is the importance of using Factory Classes?How are they different from other Java classes?

    What is the importance of using Factory Classes?How
    are they different from other Java classes? Factory is a design pattern. The idea is that you
    don't do new of a class all over your program. Instead
    you call a static method of the class which
    instatiates the class for you. So new objects are
    created within the class itself. The class has become
    a "factory" of objects of itself.
    The discussion about how-to do conditional compiling and integrate the fact that you are developing cross-platform into the code is a good example of a possible use
    Another reason you might want to implement a factory, is when a certain object is very resource hungry in some way and you can reduce and regulate the instantiations of the class by using a factory to keep handig out a set of objects. The object must be usuable in this manner though.

  • What is Factory class?

    hi friends,
    what is Factory class?
    How we can differentiate Factory class from norma java class?
    thanks,
    ramu.

    I'll take "Questions I can answer myself" for 500 thanks Alex.

  • Which is a factory class ?

    which is a factory class  here ?  Connection class or DriverManager class
    Connection con=null;
    Statement stmt=null;
    try {
         Class.forName("oracle.jdbc.driver.OracleDriver");
         con = DriverManager.getConnection("myServer", "user","password");
         stmt = con.createStatement();
    } catch(Exception e) {}

    user575089 wrote:
    I think DriverManager class. It takes inputs and returns a different connection object for different database url.
    But if I think other way , it could be Connection class as well ...They're both factories. Connection is a great example of the Abstract Factory Pattern, whereas DriverManager looks like it could just have a factory method of getConnection().
    Hence, I'm in a doubt....I think factory class should have a factory method which should take input and gives an output object depending upon input fed to it.Factory Method and Abstract Factory are two different but related patterns. Where a factory method will just return you an instance, possibly depending on some input (but not necessarily), Abstract Factory is used to create a class hierarchy of related classes.
    You can see Abstract Factory clearly when you display the actual class of the connection you get from the DriverManager.
    Depending on the database it would return for example MySQLConnection class, which would then give you MySQLStatement objects. But in your code you don't need to worry about the actual classes, since you can just use the abstract hierarchy of Connection / Statement / ResultSet etc.

Maybe you are looking for

  • Why can't i find an iCloud icon on my computer or my devices

    why can't i find an iCloud icon on my computer or my devices

  • Invalid Email Password - but its not.

    Hi - I hope you can help. I had a BB curve 8520 for past 2 years and loved it.  Over Christmas, my son had my old BB and I bought a new one - exactly the same - the Curve 8520. Both operate on orange networks.  My old BB was v4 new BB is v5.  I have

  • U00B4Business Partner Catalogue Numbers-query in SAP B1

    Hello, please, could you give me an advice where I can find a query which contents Business Partner Catalogue Numbers? I mean, I have the main supplier and a lot of "secondary" suppliers. I would like to see catalogue numbers from our system for all

  • User Prompts in SQL

    Hello everybody, I am trying to run a SELECT statement where I would like to use an input box to enter in the name of a customer in my database. However, when it runs, I just get a 'no data found' error. Here is my code: SELECT firstname, lastname FR

  • Lost Receipt for PS4, but paid with cash?

    I bought a Ps4 on 8/1/14 when I lived in San Diego area with cash but lost my receipt when I moved to Arizona in March of 2015. I have original box and serial number but need my receipt for proof of purchase for service by SONY. I just want to know i