开发者

What is the getQuery method for?

Do开发者_如何转开发cumentum sample code is never deeply commented, so my question is:

What does this line mean?

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


You can safely replace it in Java with

IDfQuery query = new DfQuery();

That approach with a factory method comes the old Docbasic days which got constrained by what COM can or cannot do


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() );
}


One can use the

  IDfQuery query = new DfQuery();

approach

The current DFC guide, however clearly recommends using the com.documentum.com.DfClientX factory class to obtain new instances of objects such as DfQuery instead of directly invoking the constructor

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜