MatasAdmoneo / CarFans

0 stars 1 forks source link

Very long Advert class constructor. #22

Open Matas-V opened 1 month ago

Matas-V commented 1 month ago

Problem: https://github.com/MatasAdmoneo/CarFans/blob/393f4589714e546ce8f3929bef5a559c3defa674/be/Cf.Application/Services/AdvertServices/UserAdvertService.cs#L47-L62

Solution: In order to create an Advert, it is required to pass a lot of parameters to the constructor. I believe it would be more maintainable to pass the model object to the constructor, for example, it is possible to refactor like this:

Advert constructor: image

Advert constructor usage: image

KasparasLu commented 1 month ago

Problem: OriginalCode

Code snipped after optimizing: image

Changes:

renaming the variables for better readability: pdfEntry (entry could be ambiguous for a new person) The method is short and single responsibility. The code itself can be optimized by inversing the if statement, no need to nest the code. (Better readability, cleaner code) The method operates within the context of a service entity, which aligns with domain-driven design (DDD) principles. The name of the method was changed to make it more intuitive.