Permalink
Browse files

make constructors private since these classes aren't meant for creati…

…ng instances
  • Loading branch information...
1 parent e0a13c8 commit 28cd1740c1874627b58fe99f126a7cfb3d729a05 @fernandezpablo85 fernandezpablo85 committed Feb 14, 2013
@@ -22,6 +22,8 @@
*/
public class OAuthConstants
{
+ private OAuthConstants(){}
kullfar
kullfar Mar 12, 2013 Owner

Maybe convert to abstract class is a better decision?
or even interface?

fernandezpablo85
fernandezpablo85 Mar 12, 2013 Collaborator

What's the benefit?

kullfar
kullfar Mar 12, 2013 Owner

In short, private constructors protects from external instantiating, but not from instantiating at all, while abstract classes and interface intended to be without ability to instantiate. (btw, private constructor can be called with reflection).

private constructor is useful if you want to restrict instantiating of class to public factory methods within class. It's not our case.

so, it's just philosophical benefit. And more readable code, ofcourse!; -)

ps.in case of interface - no need to write "public static final" on every line

+
public static final String TIMESTAMP = "oauth_timestamp";
public static final String SIGN_METHOD = "oauth_signature_method";
public static final String SIGNATURE = "oauth_signature";
@@ -7,6 +7,8 @@
*/
public class MapUtils
{
+ private MapUtils(){}
+
public static <K,V> String toString(Map<K,V> map)
{
if (map == null) return "";
@@ -23,6 +23,8 @@
ENCODING_RULES = Collections.unmodifiableMap(rules);
}
+ private OAuthEncoder(){}
+
public static String encode(String plain)
{
Preconditions.checkNotNull(plain, "Cannot encode null object");
@@ -16,6 +16,8 @@
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+");
+ private Preconditions(){}
+
/**
* Checks that an object is not null.
*
@@ -9,6 +9,8 @@
*/
public class StreamUtils
{
+ private StreamUtils(){}
+
/**
* Returns the stream contents as an UTF-8 encoded string
*

0 comments on commit 28cd174

Please sign in to comment.