jeudi 18 novembre 2021

Are fromXYZ methods inside entities an antipattern?

I am developing a Symfony-Application but I guess my question is mostly independent of framework-usage.

This is the situation:

I got a very lightweight entity that is actually not even managed by the ORM as it is just used to aggregate and communicate information of another entity.

I read that we should keep business-logic out of the model but I also thought that it would proof quite useful to me if I had a fromXYZ-method in my lightweight-entity to create a SPOC for instanciation based off of the "big entity". But technically this from-method performs logic which contradicts what I read to be good practice.

So would this be an antipattern? How would I resolve this in a more suitable way, if yes?

Aucun commentaire:

Enregistrer un commentaire