Skip to content

Instantly share code, notes, and snippets.

@jonasurbano jonasurbano/Developer Secret
Created Apr 3, 2015

What would you like to do?
Example of Pattern Factory with Java EE 7. A recruiter should choose among developers depending on their English level
import javax.enterprise.context.Dependent;
public class Developer implements Person {
public String readResume() {
return "I could be your man";
import javax.enterprise.context.Dependent;
public class DeveloperWithC1 extends Developer {
public String readResume() {
return "I'm your man";
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface EnglishLevel {
Type value();
enum Type { Intermediate, Advanced, Proficiency};
import javax.enterprise.util.AnnotationLiteral;
public class EnglishLevelLiteral extends AnnotationLiteral<EnglishLevel> implements EnglishLevel {
private static final long serialVersionUID = 1L;
private Type type;
public EnglishLevelLiteral(Type type) {
this.type = type;
public Type value() {
return type;
public interface Person {
public String readResume();
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
public class PersonFactory {
private Instance<Person> developers;
* Search among hundreds of resumes
public Person getDeveloper(EnglishLevel.Type type) {
EnglishLevelLiteral literal = new EnglishLevelLiteral(type);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.