Object creation and factories

Describes the usage of constructors in the OPL Java interface.

The C++ API allows you to create objects using a constructor. To provide greater flexibility and allow for evolution, the Java API uses a “Factory” pattern: objects are created by calls to the methods of a root object. For example, you create OPL objects using the methods of the class IloOPLFactory.createOPLModel, IloOPLFactory.createCPLEX, and so on. Similarly, you create Concert modeling constructs using the methods of the class IloMPModeler (implemented by the IloCplex class): numVar, range, minimize, and so on.

For example, the following code lines create an instance of IloNumVar:


IloMPModeler modeler=new IloCplex();
IloNumVar var=modeler.numVar(0,10);

The Concert C++ modeling API works by redefining operators to provide a compact notation for common constructs. In Java, the equivalent constructs are created through regular methods of IloModeler: ge, eq, prod, and so on.