# Code Smell 135 -  Interfaces With just One Realization

> TL;DR: Don't over-generalize

# Problems

- Speculative Design

- Complexity

- Over-Engineering

# Solutions

1. Remove the interface until you get more examples

# Context

In the past, programmers told us to design for change. 

Nowadays, We follow the scientific method. 

Whenever we find a duplication we remove it. 

Not before.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/e86499e8b367ce0d5524c347ed821cda)
```java
public interface Vehicle {
    public void start();
    public void stop();
}

public class Car implements Vehicle {
    public void start() {
        System.out.println("Running...");
    }
    public void stop() {
        System.out.println("Stopping...");
    }
}

// No more vehicles??
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/c7c06a683be5fe72d481840c2720e0d5)
```java
public class Car {
    public void start() {
        System.out.println("Running...");
    }
    public void stop() {
        System.out.println("Stopping...");
    }
}

// Wait until more vehicles are discovered
```

# Detection

[X] Automatic 

This is very easy for our linters since they can trace this error at compile time.

# Exceptions

This rule applies to inter system definition and business logic.

Some frameworks define an Interface as protocol to be fulfilled.

On our [bijections](https://maximilianocontieri.com/the-one-and-only-software-design-principle) we need to model existing real world protocols.

Interfaces are the [MAPPER](https://maximilianocontieri.com/what-is-wrong-with-software) correspondence to protocol.

Dependency injection protocols declare interfaces that are fulfilled with their realizations. Until then, they can be empty.

# Tags

- Over Design

# Relations

%[https://maximilianocontieri.com/code-smell-130-addressimpl]

%[https://maximilianocontieri.com/code-smell-136-classes-with-just-one-subclass]

# Conclusion

We need to wait for abstractions and not be creative and speculative

# Credits

Photo by [Brian Kostiuk](https://unsplash.com/photos/WZ43jnCeWOs#:~:text=Photo%20by%20Brian%20Kostiuk%20on%20Unsplash) on Unsplash

* * *

> I love software, because if you can imagine something, you can build it.

_Ray Ozzie_
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
