Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (42 sloc) 1.812 kB
namespace Rosella
{
/* A generic object factory type, that serves as the basis for other
factory types. A factory must provide a "create" method, which returns
an object of the type which the factory is responsible for. Also, the
factory should provide a "create_typed" method, to attempt creating
an object of a different type (such as a subclass).
This is the base class for other factory-like classes in Rosella.
*/
class ObjectFactory
{
var target_type;
function BUILD(var target_type [optional], int has_type [opt_flag])
{
if (has_type)
self.target_type = target_type;
else
self.target_type = null;
}
// Create an object. The default implementation throws an error.
// subclasses may do something different
function create(var pos [slurpy], var named [slurpy,named])
{
if (self.target_type != null)
return self.create_typed(self.target_type, pos:[flat], named:[flat,named]);
using Rosella.Error.invalid;
invalid("ObjectFactory.create",
"ObjectFactory: Cannot create an object without at type.\n" +
"You must provide a type to create_typed, pass one to the" +
"BUILD method of ObjectFactory"
);
}
// Create an object given a type and a list of parameters. The default
// behavior is to pass the given parameters to the object constructor.
// subclasses may do something different
function create_typed(var type, var pos [slurpy], var named [slurpy,named])
{
using Rosella.build;
return build(type, pos:[flat], named:[flat,named]);
}
}
}
Jump to Line
Something went wrong with that request. Please try again.