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

Require constructor parameters to avoid temporal coupling #97

Open
ghost opened this issue Apr 15, 2019 · 4 comments
Open

Require constructor parameters to avoid temporal coupling #97

ghost opened this issue Apr 15, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 15, 2019

At this time the POJOs do not require any specific details on creation. However, the API calls require certain values to be present.

My suggestion would be to request the values required in the constructor to avoid temporal coupling and runtime errors.

@jeevatkm
Copy link
Owner

@janoszen I think currently supported has validations for the required parameters. If I misunderstood your suggestion, could you please provide some code snippet to explain the idea?

@ghost
Copy link
Author

ghost commented Apr 15, 2019

For example:

class Droplet {
  public Droplet(
    String name,
    String region,
    String size,
    String image
  ) {
    //...
  }
}

This would make it easier to use the API.

More about temporal coupling: https://hackernoon.com/api-design-temporal-coupling-2c1687173c7c

@jeevatkm
Copy link
Owner

@janoszen Thank you for sharing your suggestion. It is helpful to define a constructor in the respective POJOs. I'm not sure when I can get to this suggestion; there are feature(s) should be added is in pending state.

FYI, the library already has validations in almost all methods I believe, for example -

public Droplet createDroplet(Droplet droplet)
throws DigitalOceanException, RequestUnsuccessfulException {
if (null == droplet || StringUtils.isBlank(droplet.getName()) || null == droplet.getRegion()
|| null == droplet.getSize() || (null == droplet.getImage()
|| (null == droplet.getImage().getId() && null == droplet.getImage().getSlug()))) {
throw new IllegalArgumentException(
"Missing required parameters [Name, Region Slug, Size Slug, Image Id/Slug] for create droplet.");
}

@ghost
Copy link
Author

ghost commented Apr 23, 2019

@jeevatkm the point of not having temporal coupling is that you don't find out runtime that something is missing, the compiler tells you immediately that you are missing something. It reduces friction and the possibility of making a mistake. Anyway, it's just a suggestion because I ran into this issue.

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

1 participant