Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

re-motion in general uses parameter lists for passing
parameters for constructors to the object factory. The
mechanism is explained in the PhoneBook tutorial for
NewObject<T> (section NewObject<T> with parameters).

For every class for which you want to have instantiation
with parameters, you must create a constructor. Let's
say you want a DessertTopping with flavors:

...

What you need is a constructor for DessertTopping that
does the right thing:

Code Block
public DessertTopping (Flavor flavor)
{
  // we assume that 'DessertTopping' now has a
  // 'Flavor Flavor' property
  Flavor = flavor;
}

You are basically set. Instantiation does ***NOT*** work like
this:

Code Block
ObjectFactory.Create<DessertTopping> (Flavor.Licorice)

...

ParamList.Create () returns a parameter list object and
is a generic, strongly typed method (although it doesn't look like it).
The object factory's Create<DessertTopping> finds the matching
constructor by reflection (if you have declared that constructor)
and calls it automatically.

If the empty parameter list (ParamList.Empty) is passed,
then the default constructor is used.