|
|
|
|
|
by ohduran
1228 days ago
|
|
I've been asking myself *this* for the year-ish I've been working with Ruby on Rails. The idea of encapsulating any piece of logic into a class function in order to call a single method is very weird, given that you can do the very same thing with just a method on a model class. Payment.process seems superior in many areas (understanding, readability, explainability) compared to PaymentProcessor.new(payment: payment).process. It dawn on me that the latter is precisely what people at Java do, and I've reached the conclusion that this way of writing software is enforced by Java developers who realized they needed to learn Ruby because their job prospects are better, and are simply retrofitting what they used to do in a new programming language. |
|
Extracting important business behaviour into objects allows applying OO (ie, powerful despatch rules) where it is valuable.
Subtyping your model to achieve many of these possible usecases would give poor design results.
For example, if payment processing were in Payment.process() the Payment entity would need to be subtyped or composed for any of 1) a different payment gateway, 2) a sales tax in a new jurisdiction, 3) a new confirmation, or 4 a new payment flow. Having all that in your model entity is probably wrong.
Simple behaviour is fine in the model, major business TN usually not.