this post was submitted on 21 Oct 2024
85 points (86.3% liked)

Programming

17416 readers
80 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] olafurp@lemmy.world 2 points 3 weeks ago (1 children)

I like the service but the constructor parameter is really bad and makes the methods less reusable

[–] dohpaz42@lemmy.world 2 points 3 weeks ago (1 children)

That’s fair. How would you go about implementing the service? I always love seeing other people’s perspectives. 😊

[–] olafurp@lemmy.world 1 points 3 weeks ago

More or less the same but the user gets passed as a method parameter each time. Validators would be in my opinion a long function inside the service also with named variables like this because it's just easy to read and there are no surprises. I'd probably refactor it at around 5 conditions or 30 lines of validation logic.

I recommend trying out using the constructor in services for tools such as a database and methods for data such as user. It will be very easy to use everywhere and for many users and whatever

const passwordIsValid = ...
if (!passwordIsValid){
  return whatever
}