DEV Community

Andrzej Karaś
Andrzej Karaś

Posted on • Originally published at karas.codes on

How to pick proper name of classes?

Did you ever ask yourself how you could save time on development stage? It would be very nice when you could implement some part of code way faster than now. Especially when you develop a lot of new features or extending existing ones. In this post I will show you very simple trick to achieve it!

Don't you try to find name before you implement a class

The trick applies to structural programming too, but we are mostly using OOP on our daily basis. So I will use class as an example.

Imagine that we want to implement a class that would be doing some complex operations for us. Let's say we gathered some requirements at the first step (I will give couple examples):

  • we want to take a photo from a webcam by using our browser extension
  • we want to process data in a way that output would be ready to show to our client
  • we want to validate URL based on rule configured by our client

In all those cases we will be able to divide code into a couple of classes. If we don't want to use meaningless names like: controller, manager, service - then we could use that simple trick

Use some temp name

Yes, that is so simple. Use 'Foo' or 'Bar' for your class, implement whole logic encapsulated by this class. Of course, you need to remember that single class should do single thing, without any side effects. Also, remember about implementing unit-tests. Implementing both of them and sticking with very small class that have single purpose of use will let you create a name very quickly - once you finish implementing it or even in the middle of the process.

Remember: change the temp name to the correct one, before merging your code into the main branch.

Hope that you found it useful!

Top comments (0)