Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (34 sloc) 1.549 kb
/* A generic object factory type which 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, albeit related, type (such as a subclass).
This is the base class for other factory-like classes in Rosella. This class
can be used directly as a generic factory type or it can be subclassed.
*/
class Rosella.ObjectFactory
{
var target_type;
function ObjectFactory(var target_type = null)
{
self.target_type = target_type;
}
// If the default target type is set, call .create_typed with it.
// Otherwise, throw an error.
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]);
Rosella.Error.error("Cannot create an object without a type.\n" +
"You must provide a type to create_typed or pass one to the " +
"constructor for 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])
{
return Rosella.construct(type, pos:[flat], named:[flat,named]);
}
}
Jump to Line
Something went wrong with that request. Please try again.