Image for post
Image for post

BETTER SOFTWARE DEVELOPMENT

What Does ‘Service’ Class Mean?

I’m sure you’ve never looked at a class called “SomethingService” and right off the bat knew exactly what it was all about.

Nicklas Millard
Aug 11, 2020 · 3 min read

Truth be told, we’re all confused.

One thing is obvious after years of professional development, wading through tons of code. Developers are terrible at naming things.

As a rookie developer, I know you feel overwhelmed, puzzled or straight-up confused whenever you meet or class in the wild — or better, .

Class names are like job titles

Vague.

Business Developer? Yeah, you’re a salesperson. Social Media Ninja? You probably got a 3-week course in how to post cat pics on Instagram and develops a “sick” SoMe strategy. Software Developer? You might as well be a code monkey. Who knows which responsibilities you’re assigned.

There’s a distinction to make. Job title and job role. We sometimes (often) like to make our titles fancier than the role we’re having.

The same goes for classes.

The service classes

Anything suffixed is basically a logic dumpster. Any new feature added to your application somehow always ends up implemented in some “service” class.

A service class takes a large number of constructor arguments, making it hugely painful to test. Having to test that new method ? Sure, it makes total sense we’ll need to mock 7 completely unrelated classes to even instantiate the service class.

If the only relies on a single constructor argument in the service class, then move it to its own class. In that way, you now have a very simple class with only one constructor argument.

Sure, it’s not as cool to have class. But at least you know exactly what it does.

Testing becomes a breeze.

The manager classes

You’ve likely met a . It manages users. Whatever that means.

Like service classes, they too are logical dumpsters. But there’s a slight difference. If the Service class is a general waste dumpster, a manager class is like a cardboard dumpster. It’s more specialized.

You’ll face the same issues dealing with unit tests as with the service classes. You’d need to mock a ton before doing the tiniest of operations.

The Utility and Helper classes

“We basically didn’t know where to put this, so here’s a class”.

These are annoying as hell. There’s not a whole lot more to say about this.

So, what should you do?

Simple. Give proper names matching the responsibilities. There’s no shame in naming a class and only have a single method. It’s simple. Everyone knows what it does. It’s easy to unit test.

Stop the code bloat and simplify those classes. Like, one method simple.

Image for post
Image for post

Nicklas Millard is a software development engineer in one of the fastest-growing banks, building mission-critical financial services infrastructure.

Previously, he was a Big4 Senior Tech Consultant developing software for commercial clients and government institutions.

Connect on LinkedIn

Image for post
Image for post

Gain Access to Expert View — Subscribe to DDI Intel

Data Driven Investor

empower you with data, knowledge, and expertise

Sign up for DDIntel

By Data Driven Investor

In each issue we share the best stories from the Data-Driven Investor's expert community. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Nicklas Millard

Written by

Tech writer with 701K+ views. Sharing my opinion and what I learn. Danish C# backend engineer in FinTech. Ex Big4 senior tech consultant.

Data Driven Investor

empower you with data, knowledge, and expertise

Nicklas Millard

Written by

Tech writer with 701K+ views. Sharing my opinion and what I learn. Danish C# backend engineer in FinTech. Ex Big4 senior tech consultant.

Data Driven Investor

empower you with data, knowledge, and expertise

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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