Why Use Case use class form rather than only method?

162 views
Skip to first unread message

Angga

unread,
Nov 19, 2021, 10:41:16 AM11/19/21
to Clean Code Discussion
Hi guys, i am still learning how to implement clean code properly. I have read some example that use case usually only have 1 method. So, why should we use class rather than method?

Paul Michael Reilly

unread,
Nov 19, 2021, 10:44:14 AM11/19/21
to Clean Code Discussion
Please ask this question on the Clean Coders Slack workspace: https://join.slack.com/t/cleancodersgroup/shared_invite/zt-937ucgo4-bSW17eLlKGb9s0~UBliguw

Łukasz Duda

unread,
Nov 19, 2021, 10:48:49 AM11/19/21
to Clean Code Discussion
I think no one said that it should be a class.
It can be.
Some examples implement use case as a command.

Łukasz Duda

unread,
Nov 19, 2021, 11:16:06 AM11/19/21
to Clean Code Discussion
why do this?
with class you can apply command design pattern
see some benefits:
  • decouples object that invokes (from how or when to execute)
  • allows you to create a sequence of commands or rollback command
on the other hand you can find reverse refactoring https://refactoring.com/catalog/replaceCommandWithFunction.html and disadvantages of command pattern
as usualy - it depends ;-)
Reply all
Reply to author
Forward
0 new messages