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()
Wiki Markup
{scrollbar}

...

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

The idea is that adapters for objects are accessed based on the actual type of an object. These adapters supply additional functionality. The adapters are located using an a StrategyRegistry (API).

The lookup of adapters is based on an inheritance search; thus providing an adapter for type java.util.Map will match any object that implements the Map interface. The inheritance search works its way up the class hierarchy looking for a matching registration. If nothing is found, then all the interfaces directly or indirectly implemented by the selector class are checked. java.lang.Object is always the final match.

...

As a special case, the value null is search searched for as if it was were an instance of the class void.

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);
}

...

Every method of the service interface should take at least one parameter. Generally, such interfaces have only one or two methods.

Example

You will usually have a service configuration for defining the adapter registry.

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

{scrollbar}
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);
  }
Wiki Markup

 

Scrollbar