digitalocean-api-java icon indicating copy to clipboard operation
digitalocean-api-java copied to clipboard

Require constructor parameters to avoid temporal coupling

Open ghost opened this issue 5 years ago • 4 comments

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.

ghost avatar Apr 15 '19 05:04 ghost

@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?

jeevatkm avatar Apr 15 '19 18:04 jeevatkm

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

ghost avatar Apr 15 '19 22:04 ghost

@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 -

https://github.com/jeevatkm/digitalocean-api-java/blob/479d2275699ef126d0c371b19f2b25716b225863/src/main/java/com/myjeeva/digitalocean/impl/DigitalOceanClient.java#L300-L307

jeevatkm avatar Apr 17 '19 18:04 jeevatkm

@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.

ghost avatar Apr 23 '19 10:04 ghost