The following is an API reference for a method in "QmlDocument" class(Blackberry10).
Builder create (const QString &qmlAsset, boolautoLoad )
Creates and returns a builder for constructing a QmlDocument instance with a parent object and an asset name to load the document from.
Parameters qmlAsset The QML asset name load the document from, specified relative to the assets root. autoLoad if true the document is automatic loaded, otherwise it is required to call load function explicitly. The default is true . Since: BlackBerry 10.0.0
Now what is exactly meant by a "Builder" here. What is its purpose? what is the difference of creating an object from QmlDocument class with "new" keyword, and creating the object with the method defined above?
Builders are usually classes defined locally to the associated class (ie QmlDocument::Builder) that allow chaning of methods with operator . ()
in a way similar to that done with iostreams and operator << ()
. What it gets you is a more readable way of createing objects (and potentially their childre) in one statment rather than creating with a new
operator and a number of function calls. A better example than QmlDocument might be the Container class:
Container *container1 = Container::create()
.preferredSize(200, 200)
.background(Color::Blue);
This creates a new Container, sets the preferred size and background color. The implementations details are hidden. Somewhat simmilar to an opaque type in C.