Skip to main content
replaced https://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

SnowmanSnowman's answer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.

Snowman's answer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.

Snowman's answer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.

replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

Snowman's answeranswer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.

Snowman's answer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.

Snowman's answer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.

Source Link
5gon12eder
  • 7.2k
  • 2
  • 25
  • 29

Snowman's answer already addresses the issue with the authentication and I agree with this advice.

Concerning the utility methods you've mentioned, I'd recommend sourcing them out into a utility class. Even if you need them only in one place at the moment, it feels wrong to have

static String toHex(byte[] data);

or

static byte[] hashSha1(byte[] data);

in an APIClient as doing these things is not part of an APIClient's genuine business. Putting them in a utility class where they can be public allows you to unit test them in isolation and perhaps re-use them later.

There is no undue cost associated with doing this. Inside the APIClient, you can refer to the static methods in the utility class directly without needing to inject this dependency. These utility functions are so simple that you probably won't ever want to stub them out for testing.

The trickiest part is probably finding a decent place for those utility methods. Sometimes, it might be tempting to throw them all together into a single Util class but this will quickly become messy. So maybe group them semantically into “text functions”, “hash functions”, etc and make sure that it will be intuitive where to look for or maybe add functionality later.