Create Factory for Node, VariableHandler and ServiceObjects
-----------------------------------------------------------

                 Key: ZETACOMP-51
                 URL: https://issues.apache.org/jira/browse/ZETACOMP-51
             Project: Zeta Components
          Issue Type: New Feature
          Components: Workflow
            Reporter: Benjamin Eberlei


Currently all the business logic related objects in ezcWorkflow create their 
dependencies using a "new $className" approach. This is bad for two reasons:

1. Its impossible to inject (expensive) dependencies into those classes such as 
database connections, webservices or re-use existing business logic by 
injecting objects. (Unless you use a static registry or singletons - which 
hurts testability).

2. Variable Handlers instances are not re-useable, leading to unnecessary 
object creation overhead in batch usage of ezcWorkflow.

Would it make sense to create a WorkflowFactory that has the following three 
methods:

{code}
class ezcWorkflowObjectFactory
{
    public function createNode($className, $configuration)
    {
         return new $className($configuration);
    }
    public function createVariableHandler($className)
    {
         return new $className;
    }
    public function createServiceObject($class, $args = null)
    {
        $class = new ReflectionClass( $class );

        if ( !$class->implementsInterface( 'ezcWorkflowServiceObject' ) )
        {
            throw new ezcWorkflowExecutionException(
              sprintf(
                'Class "%s" does not implement the ezcWorkflowServiceObject 
interface.',
                $this->configuration['class']
              )
            );
        }

        if ( !empty( $args ) )
        {
            return $class->newInstanceArgs( $args );
        }
        else
        {
            return $class->newInstance();
        }
    }
}
{code}

Which encapsulates the object creation logic that is currently present and add 
setObjectFactory()/getObjectFactory() to ezcWorkflow (defaulting to this 
implementation). The complete code can then be changed to use this factory to 
create objects.

It would then be easy to write your own implementation that extends the caching 
and/or dependency injection capabilities of ezcWorkflow.


-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to