DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > In The Age Of DRYness - Do We Really Need Naming Conventions For Interfaces?

In The Age Of DRYness - Do We Really Need Naming Conventions For Interfaces?

adam bien user avatar by
adam bien
·
Aug. 19, 09 · Java Zone · Interview
Like (0)
Save
Tweet
4.66K Views

Join the DZone community and get the full member experience.

Join For Free

During past projects / reviews I found the following naming conventions for interfaces and their realizations:

//1. 
IService service = new Service();
//2.
Service service = new ServiceImpl();
//3.
ServiceIF service = new Service();

Each one contains redundant information. Either your are emphasizing  the interface, or its implementation. The information is already contained in the source code, so both is redundant.
Such naming conventions are only necessary if you have really no idea how to name the implementation, so instead of thinking about a sound name, its easier to rely on existing template.

The lack of name for the implementation is probably also an indicator for it's unsufficient responsibilities. So if you can not find a proper name for the implementation, it is a good idea to think about removing the interface and exposing directly the implementation - then without strange conventions. Actually there are no such conventions in the JDK. The interfaces and their implementations are often even called differently:

Runnable r = new Thread();

RootPaneContainer c = new JFrame();

TableModel t = new DefaultTableModel();

Remote remote = new UnicastRemoteObject()
;

The purpose of an interface is the abstraction or decoupling from several implementations. A single implementation do not needs to decoupled with an interface. There are some exceptions from the rule, like the need to use dynamic proxies etc.

An interface realized by a single implementation with strange naming conventions shouldn't be considered as a general best practice...

From http://www.adam-bien.com

Interface (computing)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Applying Kappa Architecture to Make Data Available Where It Matters
  • How to Test JavaScript Code in a Browser
  • How to Utilize Python Machine Learning Models
  • Why I'm Choosing Pulumi Over Terraform

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo