Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class. I have already asked a question,asked a question, got some feedback and incorporated it into my code.

I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class. I have already asked a question, got some feedback and incorporated it into my code.

I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class. I have already asked a question, got some feedback and incorporated it into my code.

added 831 characters in body
Source Link
arsenal
  • 2.2k
  • 9
  • 28
  • 42

Update:-

There is one issue with your suggestion -

Suppose if I am making keys like this, then it will throw IllegalArgumentException, right? Since uuid and deviceid are null or empty but with my above rules, if userId is set and it is set with proper value, then it should not throw IllegalArgumentException. Meaning if userId is set, then I will validate userId to see whether it is <= 0 or not.

DataKey keys = new DataKey.Builder(100).setUserId(1234L).setUuid("").setDeviceId(null).build();

There is always a priority, userId takes the priority first, then uuid takes the priority and then deviceId takes the priority.

If userId is set, then I will validate userId, but if userId is not set and uuid is set, then I will validate uuid but if userId and uuid is not set, then I will validate deviceId.

Update:-

There is one issue with your suggestion -

Suppose if I am making keys like this, then it will throw IllegalArgumentException, right? Since uuid and deviceid are null or empty but with my above rules, if userId is set and it is set with proper value, then it should not throw IllegalArgumentException. Meaning if userId is set, then I will validate userId to see whether it is <= 0 or not.

DataKey keys = new DataKey.Builder(100).setUserId(1234L).setUuid("").setDeviceId(null).build();

There is always a priority, userId takes the priority first, then uuid takes the priority and then deviceId takes the priority.

If userId is set, then I will validate userId, but if userId is not set and uuid is set, then I will validate uuid but if userId and uuid is not set, then I will validate deviceId.

added follow up sentence and link to prev post.
Source Link
Vogel612
  • 25.3k
  • 7
  • 58
  • 141

I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class. I have already asked a question, got some feedback and incorporated it into my code.

I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class.

I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class. I have already asked a question, got some feedback and incorporated it into my code.

added 118 characters in body
Source Link
arsenal
  • 2.2k
  • 9
  • 28
  • 42
Loading
added 4 characters in body
Source Link
arsenal
  • 2.2k
  • 9
  • 28
  • 42
Loading
added 135 characters in body
Source Link
arsenal
  • 2.2k
  • 9
  • 28
  • 42
Loading
added 9 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
Loading
added 162 characters in body
Source Link
arsenal
  • 2.2k
  • 9
  • 28
  • 42
Loading
Source Link
arsenal
  • 2.2k
  • 9
  • 28
  • 42
Loading