@kaia I don't know the language you're working in but yea... that is generally the way to go.
Functions help keeping your code "DRY" ("Don't Repeat Yourself").
Classes can help with SRP ("Single Responsibility Principle") where 1 class does 1 thing and is very good at it.
As for the "how do you know what each returns: In most languages, you can define that and most editors will be able to show it.
In the screenshot here, my function returns an instance of the "ReponseBuilder".