On Jan 6, 2010, at 5:19 PM, Marius Dumitru Florea wrote:
Vincent Massol wrote:
Hi,
This is the current interface:
public interface EntityReferenceFactory<T>
{
/**
* @param entityReferenceRepresentation the representation of an entity reference (eg
as a String)
* @param type the type of the Entity (Document, Space, Attachment, Wiki, etc) to
extract from the source
* @return the resolved reference as an Object
*/
EntityReference createEntityReference(T entityReferenceRepresentation, EntityType
type);
}
Now we have 2 different implementations:
- one for which T = String
- one for which T = EntityReference (our normalizer)
In term of usage this means:
EntityReference ref = factory.createEntityReference("wiki:space.page",
EntityType.DOCUMENT);
EntityReference ref = factory.createEntityReference(documentReference,
EntityType.DOCUMENT);
The last example is used to normalize the passed reference, convert it into the type
specified by the second parameter, filling the blanks.
I feel that Factory is no longer an appropriate name, especially for the second use case.
WDYT?
IMO a better name would be Resolver, Normalizer, or Converter. Any other better name? (I
haven't put Parser since I don't believe it's correct).
Examples:
EntityReference ref =
resolver.resolve("wiki:space.page", EntityType.DOCUMENT);
EntityReference ref = resolver.resolve(documentReference, EntityType.DOCUMENT);
+0 for Resolver. I find the unification between the factory and the
normalizer a bit unnatural.
The Factory is not really a factory since:
1) It takes the definition in param. It's more a Parser or a Converter/Resolver.
2) A Factory is there to return an interface and have different implementations returning
different implementing classes for the return interface. See
http://en.wikipedia.org/wiki/Factory_method_pattern
Thanks
-Vincent
Thanks,
Marius
>
> EntityReference ref = normalizer.normalize("wiki:space.page",
EntityType.DOCUMENT);
> EntityReference ref = normalizer.normalize(documentReference, EntityType.DOCUMENT);
>
> EntityReference ref = converter.convert("wiki:space.page",
EntityType.DOCUMENT);
> EntityReference ref = converter.convert(documentReference, EntityType.DOCUMENT);
>
> It's quite a lot of work to change what I have put but since this is an important
API we need to be sure of what we want since we won't be able to change it later on.
>
> I'm +1 for Resolver.
>
> WDYT?
>
> Thanks
> -Vincent