I want to display the product, and the product card has a lot of information about the product and the owner. How to deal with Law of Demeter in this product - owner relationship?
In controller I currently have:
Product product = productRepository.get(1);
And in template:
product.name
product.description
product.owner.name
product.owner.address
But the last two calls break the Law of Demeter.
So I should be in class Product add getters:
getOwnerName()
getOwnerAddress()
And in template:
product.name
product.description
product.ownerName
product.ownerAddress
But if I have, for example, 10 information about the author, I have to do as many as 10 additional getters, which only duplicate the code.
Maybe better way would be in controller:
Product product = productRepository.get(1);
Owner owner = ownerRepository.get(product.ownerId);
And in template:
product.name
product.description
owner.name
owner.address
But will then such a structure be coherent for another programmer?
How should this be done in professional applications?