|
|
It seems to me that there is a very fine line between what a ‘Resolver’ does and a ‘Factory’. Is there an official definition of these terms (and of course other similar terms) so that we use them correctly?
My current understanding is the following:
Resolver:
Used to look up, or resolve, an existing object based on input criteria. (i.e. ViewResolver). Note that the Spring ViewResolver interface documentation states that some of them in fact create a view instead of just resolving an existing one.
Factory:
Used to create an object based on input criteria. It is often used in place of a simple ‘new’ object creation such that control of the creation of complex object structures can be controlled. (i.e. MyDomainObjectFactory)
As a specific example, we have domain models that have different validation rules depending on how they are used. Therefore, we want to supply a different ‘Validator’ depending on the context.
Should we create a 'Resolver' or 'Factory' to do this?
public interface ValidatorResolver
{ Validator resolveValidator( Object validationContext );
}
... or
public interface ValidatorFactory
{ Validator createValidator( Object validatorContext );
}
... or something else?
Thanks…
Jim Leask
It seems to me that what you described is the common understanding. A resolver (more commonly known as a locator) focuses on locating existing entities while a factory focuses on creating new entities. |
|