Should interfaces be named with Interface suffix? And abstract classes with Abstract prefix?

Let’s think for a while — where do we use class/interface name?

  • During creating object from the class (new Product(...))
  • In usage

Creating objects

We aren’t able to create objects from abstract classes and interfaces, so it is always without prefix/suffix. I hope no one suggest to call a concrete class a new ClassProduct(...), but rather new Product(...).

OOP

I’d like to introduce a philosophical note here. What is object-oriented programming about? I believe that OOP is about

Encapsulating data by behavior.

Behavior means we use methods of objects, not their properties.

Usage

Let’s consider following code

class CartItem {
private string $productId;
private int $amount;
public function price(Prices $prices): Price {
$unitPrice = $prices->unitPrice($this->productId);
return $unitPrice->multiply($this->amount);
}
}

What is the Prices? Is it a class? Is it an abstract class? Is it an interface?

We don’t know.

And we don’t care!

The only think we care is

  • What it represents? It represents prices.
  • What method it provides? It provides unit price by a product ID.

Would the readability improve if we added prefix/suffix?

public function price(PricesInterface $prices): Price {public function price(AbstractPrices $prices): Price {

I don’t see a value in such naming. The original variant is simpler and easier to read.

public function price(Prices $prices): Price {

Conclusion

When we use a certain concept, we care only about WHAT it represents and WHAT methods it provide. We don’t care whether it is a class, abstract class or interface.

Therefore I suggest to not use prefixes/suffixes for interfaces and abstract classes.

I suggest to spend more time on good naming instead.

--

--

--

Carvago is a large tech company and this publication focuses on topics related to development, design, analysis and architecture of our systems.

Recommended from Medium

Monitoring Hyperledger Fabric components using Prometheus

{UPDATE} Food Circle?Fun Cooking Games Hack Free Resources Generator

Mscape.io: A community-driven panorama of the metaverse

Multi master kubernetes on containerd with haproxy/nginx/envoy load balancer

Notes on Sarter and Woods’ “Autonomy, Authority, and Observability: Properties of Advanced…

Duro’s Cloud PLM Hits Onshape App Store, Giving Teams Complete Cloud Product Management

[LeetCode] (Easy) 118. Pascal’s Triangle 119. Pascal’s Triangle II

Introducing: firebase feature flags for Jira

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Svaťa Šimara

Svaťa Šimara

Developer interested in Domain-Driven Design & Modeling

More from Medium

Mediator Design Pattern with .NET CORE

Implementing API Project In .NET Part 1 Onion Architecture

Observer Pattern

Datagrip, Mongodb Javascript and C# Mongo Driver