Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builder api #3

Open
magro opened this issue Dec 24, 2014 · 2 comments
Open

Add builder api #3

magro opened this issue Dec 24, 2014 · 2 comments

Comments

@magro
Copy link
Contributor

magro commented Dec 24, 2014

It would be nice to have a builder like this:

JsonHomeClient.Builder()
  .addHost("host", DirectLinkRelation("rel"), TemplateLinkRelation("rel"))
  .addHost(...)
  .withWSClient(WS.client)
  .withCaching(1 minute, Akka.system)
  .build()
@lichtsprung
Copy link
Member

What would be the return value of build()?

The example suggests that the Builder should be part of the JsonHomeClient object. So my guess for the type of the return value would be JsonHomeClient.
But JsonHomeClient handles just one host and and is not concerned with caching the json home document. That is why I would expect this kind of Builder in JsonHomeService where build() returns a new JsonHomeService instance.

@magro
Copy link
Contributor Author

magro commented Dec 29, 2014

According to issue #1 I'd rename JsonHomeService to JsonHomeClient, and perhaps just get rid of what's right now JsonHomeClient.
The result of build() would be AsyncJsonHomeClient (if withCaching is not used) or JsonHomeClient if withCaching is used - withCaching would change the interface to a sync/blocking one. Perhaps then the Builder should be an AsyncJsonHomeClient.Builder...

magro referenced this issue in lichtsprung/jsonhomeclient Dec 29, 2014
Adds a typesafe builder pattern to enable the
user to write code like this:

JsonHomeService.Builder()
        .addHost("http://host", DirectLinkRelationType("rel"), TemplateLinkRelationType("rel2"))
        .addHost("https://host2", DirectLinkRelationType("rel3"))
        .withWSClient(WS.client)
        .withCaching(system)
        .withUpdateInterval(1.minute)
        .withStartDelay(2.minutes)
        .build()

 The implementation uses phantom types and implicit conversions
 to ensure that all necessary parameters are passed to the
 builder before build() can be called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants