DEV Community

Cover image for Code Smell 130 - AddressImpl
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

5 2

Code Smell 130 - AddressImpl

It is nice to see a class implementing Interfaces. It is nicer to understand what it does

Code Smell 130 - AddressImpl

TL;DR: Name your classes after real-world concepts.

Problems

Solutions

  1. Find the correct name using the MAPPER

Context

Some languages bring idioms and common usages against good model naming.

We should pick our names carefully.

Sample Code

Wrong

public interface Address extends ChangeAware, Serializable {

    /**
     * Gets the street name.
     *
     * @return the street name
     */
    String getStreet();
    //...
}

//Wrong Name - There is no concept 'AddressImpl' in real world
public class AddressImpl implements Address {
    private String street;
    private String houseNumber;
    private City city;
    //..
}
Enter fullscreen mode Exit fullscreen mode

Right

//Simple
public class Address {
    private String street;
    private String houseNumber;
    private City city;
    //..
}


//OR
//Both are real-world names
public class Address implements ContactLocation {
    private String street;
    private String houseNumber;
    private City city;
    //..
}
Enter fullscreen mode Exit fullscreen mode

Detection

[X] Automatic

Since this is a naming smell.

We can search using regular expressions and rename these concepts.

Tags

  • Naming

Conclusion

We should pick class names according to essential bijection and not follow accidental implementation.

Do not call I to your interfaces.

Relations

More Info

Credits

Photo by Paula Hayes on Unsplash


Encoded names are seldom pronounceable and are easy to miss-type.

Robert C. Martin


This article is part of the CodeSmell Series.

DevCycle image

Ship Faster, Stay Flexible.

DevCycle is the first feature flag platform with OpenFeature built-in to every open source SDK, designed to help developers ship faster while avoiding vendor-lock in.

Start shipping

Top comments (0)

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server ⏰

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Sign in to DEV to enjoy its full potential—unlock a customized interface with dark mode, personal reading preferences, and more.

Okay