Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:03:52+00:00 2026-05-23T00:03:52+00:00

In his book Effective Java , Joshua Bloch recommends against using Interfaces to hold

  • 0

In his book Effective Java, Joshua Bloch recommends against using Interfaces to hold constants,

The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class’s exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the con-stants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface.

His reasoning makes sense to me and it seems to be the prevailing logic whenever the question is brought up but it overlooks storing constants in interfaces and then NOT implementing them.

For instance,

public interface SomeInterface {
    public static final String FOO = "example";
}

public class SomeOtherClass {
    //notice that this class does not implement anything
    public void foo() {
        thisIsJustAnExample("Designed to be short", SomeInteface.FOO);
    }
}

I work with someone who uses this method all the time. I tend to use class with private constructors to hold my constants, but I’ve started using interfaces in this manner to keep our code a consistent style. Are there any reasons to not use interfaces in the way I’ve outlined above?

Essentially it’s a short hand that prevents you from having to make a class private, since an interface can not be initialized.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:03:53+00:00Added an answer on May 23, 2026 at 12:03 am

    I don’t think a class with a private constructor is any better than using an interface.

    What the quote says is that using implements ConstantInterface is not best pratice because this interface becomes part of the API.

    However, you can use static import or qualified names like SomeInteface.FOO of the values from the interface instead to avoid this issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to Scott Meyers, in his Effective STL book - item 46. He claimed
In his book Pro C# 2008 and the .NET 3.5 Platform , Andrew Toelsen
Douglas Crockford wrote in his book (Page 4): Throughout the book, a method method
After reading Jossutis' explanation on auto_ptr from his STL book I've got a strong
I have read Marcus Zarra's chapter on multithreading in his Core Data book and
I am trying to use Tarek Ziadé's Trac buildout recipe from PyPi (and his
My understanding is that Actice Record is based on a object-relational mapping (ORM) pattern
Does anyone know if there is a compilation of check style rules that covers
Should I run a classic VB6 app thru the upgrade wizard in VS08 or
How to create an empty object in R? [edit: I don't know how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.