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 static complete method that takes partial and returns full config #54

Closed
wants to merge 3 commits into from

Conversation

qinfchen
Copy link
Contributor

@qinfchen qinfchen commented Oct 4, 2017

No description provided.

@@ -35,6 +35,23 @@ public static ServiceConfigurationFactory of(ServicesConfigBlock services) {
return new ServiceConfigurationFactory(services);
}

public static ServiceConfiguration create(PartialServiceConfiguration partial) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like a ServiceConfigurationFactory#create method ought to return a ServiceConfigurationFactory, rather than a ServiceConfiguration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions on the method name? since it is a factory class, i thought using create to return a ServiceConfiguration would be appropriate. maybe be get?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about complete?

@ash211
Copy link
Contributor

ash211 commented Oct 4, 2017

Fixes #32

@qinfchen qinfchen changed the title add static create method that takes partial and returns full config add static complete method that takes partial and returns full config Oct 5, 2017
@@ -35,6 +35,24 @@ public static ServiceConfigurationFactory of(ServicesConfigBlock services) {
return new ServiceConfigurationFactory(services);
}

/** returns a complete {@link ServiceConfiguration} for the given partial one. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Javadoc / throws IllegalArgumentException to signal to caller when / how this can fail

@throws IllegalArgumentException when the given partial's security configuration is absent

@qinfchen
Copy link
Contributor Author

qinfchen commented Oct 6, 2017

any additional comments?

*
* @throws IllegalArgumentException when the given partial's security configuration is absent
*/
public static ServiceConfiguration complete(PartialServiceConfiguration partial) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little scared of this method since it's very likely we're going to forget updating it when optional fields are added to ServiceConfiguration. Absent a proposal for making this compile-time or test-time safe, I'd prefer not taking this change at the expense of a little more consumer code (need to go through ServiceConfigBlock).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The current propagateDefaults method would have the same concern as mentioned. Since there is no compile-time or test-time safe, the consumer code will be prone to the same mistake, no?. Since partial and complete configurations only differ by the optionality of one property, would a common interface between them be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping? I can help with whatever proposal we can come up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the propagate method has the same problem, but at least it's only one place rather than two. We could remove or deprecate the builder and use full constructors, at least internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works. Could the pattern like below (from the Immutables doc) be another solution?

interface Vehicle {
}

interface VehicleBuilder {
  // Generated builders will implement this method
  // It is compatible with signature of generated builder methods where
  // return type is narrowed to Scooter or Automobile
  Vehicle build();
}

@Value.Immutable
public abstract class Scooter implements Vehicle {
  public abstract static class Builder implements VehicleBuilder {}
}

@Value.Immutable
public abstract class Automobile implements Vehicle {
  public abstract static class Builder implements VehicleBuilder {}
}

class Builders {
  void buildIt(VehicleBuilder builder) {
    Vehicle vehicle = builder.build();
  }

  void use() {
    buildIt(ImmutableScooter.builder());
    buildIt(ImmutableAutomobile.builder());
  }
}

@uschi2000
Copy link
Contributor

uschi2000 commented Oct 16, 2017 via email

@iamdanfox iamdanfox closed this May 1, 2019
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

Successfully merging this pull request may close these issues.

5 participants