DEV Community

Discussion on: Write clean Object-Oriented code by replacing conditional with polymorphism

Collapse
epigene profile image
Augusts Bautra

Great stuff!
I am not a fan of putting non-AR classes in app/models though. I believe there is value in only having AR classes there, by convention. Perhaps app/value_objects is a better place for extracts like that.

Collapse
alexandreruban profile image
Alexandre Ruban Author

Hey! Thank you very much for your comment!

We could move non-ActiveRecord models in app/value_objects if we wanted to. However, when looking at a Ruby object, we feel more concerned about what it does - the methods it responds to - rather than its class/inheritance hierarchy.

When you look at the Rails source code, you can see that some non-ActiveRecord objects like ActiveStorage::Variant are in app/models. DHH also says that all models are not necessarily ActiveRecord in his great video series "On writing software well"; I highly recommend it if you want to see a bit of Basecamp's code!