Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails name convention for service objects

Usually I use nouns when I give names to my classes. I gave a noun derived from a verb like 'worker' or 'purchaser' as name for my service objects. During a code review it was said that it is common to gave verbs as names for service objects like 'work' 'purchase'.

Which direction should I follow?

Here is another oppinion against verbs:

Mostly it doesn't make sense from a standpoint of clarity and natural language to use verbs. Let's say you have model Product and you want a service object that will handle pricing on some complex criteria (geolocation, color, shipping, moonphase, etc). It would be a good candidate for a service object ProductPricingService. You wouldn't just call it Price or Pricing. First of all it's ambigious. Pricing of what? Products that you sell? Pricing you get from vendors? Pricing of gas today? And if you were to argue that this Service object could be used by many models, then you are defeating the purpose of Service Object. I'm exaggerating of course. But the whole point is to create clear and maintainable code. So while you can save some keystrokes by naming it Price, it's much more clear to another person ( and you in 5 months) if you name it ProductPricingService.

Here is an oppinion against deverbal nouns

You can use something like InvoiceFinder instead of FindInvoice, but I found out that putting the action at the end led to awkward named classes, so putting the verb at the beginning made them cleaner.

like image 488
Boti Avatar asked Nov 19 '13 08:11

Boti


1 Answers

I think your original one, using deverbal nouns makes more sense. You should use verbs for method names.

like image 103
sawa Avatar answered Sep 23 '22 17:09

sawa