I can't decide what to name my class. So far I've labelled it up as a Factory, but I am not sure.

Here is the class. As you can see, it exists to return a concrete type of an Interface (ResolveRegistrationIssue) based on the argument supplied to the getter method (ResolutionFamilyEnum):

@ManagedBean(name = "resolveIssuesFactory")
public class ResolveIssuesFactory implements Serializable {

    @ManagedProperty(value = "#{resolvePrimaryIssuesFactory}")
    private ResolvePrimaryIssuesBean resolvePrimaryIssuesBean;

    @ManagedProperty(value = "#{resolveSecondaryIssuesBean }")
    private ResolveSecondaryIssuesBean resolveSecondaryIssuesBean ;

    @ManagedProperty(value = "#{resolveTertaryIssuesBean }")
    private ResolveTertaryIssuesBean resolveTertaryIssuesBean ;

    public ResolveRegistrationIssue getResolutionBean(
            ResolutionFamilyEnum familyEnum) {

        //null safety
        if(null ==familyEnum) {
            throw new IllegalArgumentException("The family which determines the Resolution Bean to be used may not be null.");

        if (familyEnum.equals(ResolutionFamilyEnum .PRIMARY)) {
            return resolvePrimaryIssuesBean;
        } else if (familyEnum.equals(ResolutionFamilyEnum .SECONDARY)) {
            return resolveSecondaryIssuesBean;
        } else if (familyEnum.equals(ResolutionFamilyEnum .TERTERY)) {
            return resolveTertaryIssuesBean;
                    } else {
            throw new IllegalArgumentException("Could not determine the correct Resolution Issue bean for the provided family.");

Now, I understand that a Factory class accepts arguments which define the entity to be developed and then delivered (returned).

However in my case, my entities are already developed, as they are EJB references. Thus this method only delivers them.

So is this still a Factory?

  • Look at flyweight pattern and consider the naming of the classes in the examples. – user40980 Jul 25 '13 at 14:54
  • 1
    The internal implementation doesn't matter. – Dunk Jul 25 '13 at 17:31
  • Thanks, you saved me from typing up this question myself. I have entities which are stored in an identity map so each distinct ID only has one instance; the first time you call the factory method with a certain ID you would get a new instance (which gets added to the identity map) and each successive time you would get the same instance already loaded from the map. – rory.ap Mar 24 '16 at 14:21

This looks to be more related to the Service Locator pattern.

While you are not using JNDI as the registry, your class is acting as one. This is not a flyweight pattern though. It doesn't look like this implementation is meant to save memory. It is meant to look-up instances to "services" based on an Enumeration.

  • The "create if not created but otherwise return reference" nature of this pattern makes me feel that this is the most natural fit. Thanks – 8bitjunkie Jul 26 '13 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.