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

Part 3: Solution for distributed coordination & distribution.

DevOps Tutorial | DevOps with Docker, Kubernetes and Azure DevOps

Meesho Interview Rounds three Experiences [2–5 Years Experience] [ Date May-Oct]

Odoo-15 installation and configuration in PyCharm

Feedback

AWS Certified Database Specialty DBS-C01 Exam Questions 2021 Part 2

AWS Certified Database Specialty DBS-C01 Exam Questions 2021 Part 2

In 2022, The Most In-Demand And Highest-Paying IT Jobs

175 Top Civil Engineer Interview questions asked in Top Companies | Civil Engineering Interview…

175 Top Civil Engineer Interview questions asked in Top Companies | Civil Engineering Interview Question and Answers

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

Components.js is great, but it’s very unreadable

LC 56 [Medium]: Merge intervals

The Pragmatic Programmer EP.2 — A pragmatic concept

Making Assertions On A Stub For Consecutive Calls