Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

bingzer/patterns-implementor

Repository files navigation

patterns-implementor

Simple patterns that forces the uses of Interfaces rather than concrete classes. Given:

public interface Shape { ... }
public interface Rectangle extends Shape { ... }
public interface Circle extends Shape { ... }

Implementations:

/* package */ class RectangleImpl implements Rectangle { ... }
/* package */ class CircelImpl implements Circle { ... }

Create the implementor:

public class ShapeFactory extends ImplementorFactory<Shape> { 
  public ShapeFactory() throws ImplementorException {
    addImplementation(CircleImpl.class);
    addImplementation(RectangleImpl.class);
  }
  
  @Override
  protected <E extends Shape> E newInstance(Class<E> clazz) throws InstantiationException, IllegalAccessException {
    return clazz.newInstance();
  }
}

Then use it

...
ShapeFactory factory = new ShapeFactory();

Circle circle = factory.getImplementation(Circle.class);
// circle is CircleImpl.class

Rectangle rect = factory.getImplementation(Rectangle.class);
// rect is RectangleImpl.class
...

Gradle

dependencies {
    compile 'com.bingzer.android.patterns:implementor:1.0.0'
}

About

Implementor Patterns

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published