Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Scrollbar

The StrategyBuilder Service provides a convenient way to create an implementation of the Strategy design pattern.

Div
stylefloat:right
titleRelated Articles
classaui-label
Content by Label
showLabelsfalse
showSpacefalse
titleRelated Articles
cqllabel = "service-builders" and space = currentSpace()

Another of the Gang Of Four patterns, the strategy pattern as implemented in Tapestry IoC is a kind of late binding.

...

The StrategyBuilder service (API) creates a service implementation around a strategy registry.

Code Block
java
java
public interface StrategyBuilder
{
    <S> S build(StrategyRegistry<S> registry);
}

For a given interface (and matching StrategyRegistry), a service implementation is created. The service interface is determined from the strategy registry.

...

You convert the configuration into a StrategyRegistry, and use that to build the final service:

Code Block
java
java
  public static MyStrategyService build(Map<Class, MyStrategyService> configuration,
    @InjectService("StrategyBuilder")
    StrategyBuilder builder)
  {
     StategyRegistry<MyStrategyService> registry = StrategyRegistry.newInstance(MyStrategyService.class, configuration);
  
     return builder.build(registry);
  }

 

Scrollbar