Question

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):

@SuppressWarnings("serial")
@ManagedBean(name = "resolveIssuesFactory")
@ViewScoped
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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
scroll top