0

I'm struggling on how to name classes for use cases. Because I know that is "bad" to use verbs in classes names(Uncle Bob) but at the same time names of use case classes should explain what they do(Clean Architecture). So if I have an use case "create user" Is it ok to name it " Class CreateUserUseCase" or how should I name it?

3
  • 1
    "CreateUser" is not a class name; it is a method name. Classes and Use Cases are not at all the same thing; they're not even similar. Apr 16, 2022 at 17:47
  • 4
    It sounds like it's too early in your language learning to be thinking about Uncle Bob's principles. I suggest you work with JavaScript for awhile, build some small programs, build some slightly larger programs and get comfortable with the language first. At that point, you might study Uncle Bob's principles as suggestions. Apr 16, 2022 at 17:50
  • 1
    To follow up on Robert Harvey's comments - I guess it would help if, instead of thinking of UncleBob's use cases/interactors as being mapped 1-to-1 to the fine grained usage scenarios like "create user", think of them rather as classes that you end up with if you try your best to keep separate the code with usage scenarios that aren't closely related to each other (e.g. don't make one big class that has functions for everything your application can do). Doing that is IMO more likely to get you closer to Clean Arch., compared to what you're doing now. Apr 16, 2022 at 20:49

1 Answer 1

2

I would not tack “use case” or “interactor” on to the name. A name should not be cluttered with clues about where it goes or what kind of thing it is. It should just say what it is. It should leave me unsurprised by what I find inside. It should not dictate what the outside world around it is like.

If you have a class whose only job is to be the interactor in the user creation use case then a good name might be UserCreator or UserCreation.

BTW. The Use Case or UC classes you see in Uncle Bobs interactor layer in some of his videos (he’s called them other things) are not the names you’d use in a real project. Pick a name that means something in your code base.

Not the answer you're looking for? Browse other questions tagged or ask your own question.