Skip to content

A simple utility for exposing well define package modules as factories.

Notifications You must be signed in to change notification settings

peachjean/packtory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

packtory

A simple utility for exposing well define package modules as factories.

Point

This is basically a tool to easily enable a design pattern that I am currently toying with. The idea is to treat packages as individual modules - they each have an entry point and dependencies. Within a package we may use DI to compose the objects that make it up, and dependent modules may use DI to pull in our package. However, the exact flavor of DI that we use is an implementation detail of the package, and in no way restricts usage outside of our package.

We basically generate a standard Factory class for package. This Factory class, using standard constructor- style injection, declares its dependencies and makes the entry point available via a no-arg, create method.

I hope to be able to support multiple DI strategies within the package, and expose a simple utility for visualizing an entire object graph, that spans DI strategies.

Usage

Create your entry point, SimpleEntryPoint.java:
package simple;

public interface SimpleEntryPoint
{
	public String getUpperCased();

	public String getLowerCased();
}
Create your implementation, SimpleEntryPointImpl.java:
package simple;

class SimpleEntryPointImpl implements SimpleEntryPoint
{
	private final String baseString;

	SimpleEntryPointImpl(final String baseString)
	{
		this.baseString = baseString;
	}

	public String getUpperCased()
	{
		return this.baseString.toUpperCase();
	}

	public String getLowerCased()
	{
		return this.baseString.toLowerCase();
	}
}
Finally, create a package-info.java:
@Factory(entryPoint = SimpleEntryPoint.class, composition = SimpleEntryPointImpl.class)
package simple;

import net.peachjean.packtory.Factory;
At compile time, packtory will create a factory for your package:
package simple;

@javax.annotation.Generated(value = "packtory", date = "2014-03-07T14:21-0600")
public final class Factory {

  private final String string;

  @javax.inject.Inject
  public Factory(String string) {
    this.string = string;
  }

  public final SimpleEntryPoint create() {
    return new simple.SimpleEntryPointImpl(string);
  }
}

As we add more interesting strategies, other than "a simple implementation class" this gets more interesting.

Todo

  • COMPLETE Make the DI strategy plugability actually work

  • COMPLETE Cleanup the CompositionHandler design

  • Support more DI strategies

  • Dagger

  • Guice

  • Spring

  • Dependency graph visualization

  • should treat packages as "subgraphs" with clear relationships

  • should recognize packtory packages and expand them, even if not in the same compile

  • Support multiple entry points

  • This is a departure from the pattern, but it WILL come up.

About

A simple utility for exposing well define package modules as factories.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published