Search code examples
documentumdfc

What is the getQuery method for?


Documentum sample code is never deeply commented, so my question is:

What does this line mean?

IDfQuery query = DfcUtils.getClientX().getQuery();

Solution

  • An answer to an old question, but the original poster asked what the line means, not what alternatives may be used.

    The line is creating an instance of an IDfQuery implementation, from a factory method within an instance of an object created by the static factory method within a DFCUtils class. This object is then assigned to a variable.

    So: -

    • DfcUtils = A class that contains a static method called getClientX()
    • getClientX() = a static factory method that returns an instance of an object
    • getQuery() = a factory method within the object returned by getClientX(), that returns an object that implements IDfQuery;
    • query = The variable used to reference the new IDfQuery instance

    This is a typical factory pattern, where the method/function getQuery() determines what object type to return, based on rules or configuration settings. This is preferable than creating an instance of a concrete class, when several implementations of an interface are available. Typically, a factory will act like a class bootstrapper, initializing properties before returning the object to you.

    Essentially, you may have a factory method containing a condition such as a switch statement that chooses which implementation to return, know as IOC (Inversion of control): -

    public static IDfQuery getQuery(){
        IDfQuery returnValue;
    
        switch ( getDayOfWeek() ) {
            case "Monday" :  returnValue = new MondayQuery(); break;
            case "Tuesday" :  returnValue = new TuesdayQuery(); break;
            case "Wednesday" :  returnValue = new WednesdayQuery(); break;
            case "Thursday" :  returnValue = new ThursdayQuery(); break;
            case "Friday" :  returnValue = new FridayQuery(); break;
            case "Saturday" :  returnValue = new SaturdayQuery(); break;
            case "Sunday" :  returnValue = new SundayQuery(); break;
            default: returnValue = null; break;
        }
    
        return returnValue;
    }
    
    public static String getDayOfWeek(){
        return new SimpleDateFormat("EEEE").format( new Date() );
    }