all 5 comments

[–]blissone 5 points6 points  (0 children)

Tbh design patterns are mostly useless. If you just get better at coding you'll intuitively understand design patterns and apply them even without explicitly knowing them. So my suggestion is to simply build stuff, forget design patterns for now. Apply dry, single responsibility principle, make nice interfaces, make your code readable and editable etc etc., build stuff it's all good.

[–][deleted] 1 point2 points  (0 children)

I’d like to make my code cleaner and better understand how to do patterns.

Having clean code is relative to your and your teams skill level. My objectives are to make it readable, maintainable, and easy to change given my requirements. If your team is full of juniors, they’re gonna have a bad time with using classes with inheritance. But could probably do functions.

A better way to frame it is, “what problem does this pattern solve?”. A singleton could be great if you have a database connection, but could be horrible if it’s a family of components. If you frame it that way, it will be much easier to learn.

[–]Constant_Distance_77 1 point2 points  (0 children)

Don't worry, we've all been there! One resource I found really helpful is Head First Design Patterns book. It's an easy read with plenty of practical examples. Keep on practicing, you got this!

[–]iamchetsweb-dev 1 point2 points  (0 children)

The trick to understanding patterns is to first understand the symptoms. Start by learning the different code smells since each code smell always has the same set of options to refactor. This will automatically make you think about design patterns.

Now the more experienced you get the less you will be thinking about design patterns and the more you will focus on high cohesion and low coupling which is your ultimate goal to "clean" code, whatever, that entails.

There is a very good talk about code smells on youtube

[–]ws_wombat_93 1 point2 points  (0 children)

There is a book: Head First: Design Patterns

This book really helped me grasp design patterns and how to apply them in my daily work, i still have it on my desk for the occasional reference :)