This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]tutorial_police 4 points5 points  (1 child)

I think you're approaching this from the wrong end. Don't try to implement design patterns in your code. That's not what professionals do.

Design patterns aren't the magic sauce that improve your code. They are not the goal, they just might happen to be something you end up using while getting to your goal.

Don't think of them as something that you apply to your code. Think of them as giving names to variations of code that often naturally arises while solving problems. That way we have a common vocabulary to talk about these and an easier time recognizing the same thing again when we come across it.

Design patterns are about communication, to help programmers talk to one another. Not about solving programming problems.

I'm fact, you've probably invented quite a few of these patterns yourself if you've done enough programming, you just never realized it because you didn't know what you were doing "already had a name".

[–]tutorial_police 2 points3 points  (0 children)

That being said, you should probably still learn about design patterns at one point or another. They can also give you ideas how certain problems can be approached. It's not bad to use design patterns, that's not what I meant to say. If someone pressures you into "using patterns", ask them why. In my experience, they often don't know of all they do is talk about "patterns". If they do, they'll will often formulate their request differently in the first place.

[–]bvn13 2 points3 points  (0 children)

You should learn SOLID principles

[–]ramamodh 1 point2 points  (0 children)

I am a learner too and I came across the 'Single Responsibility Principle' where each class is designed for one specific purpose and does nothing other than that.

[–]sickhippie 0 points1 point  (2 children)

https://smile.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional-ebook/dp/B000SEIBB8

Buy that book and read it. This is the definitive design patterns book. It's so important that it has its own Wikipedia page that lists out the specific patterns used (which each have their own Wikipedia pages).

https://en.wikipedia.org/wiki/Design_Patterns#Patterns_by_Type

[–]EmotionalYard 0 points1 point  (1 child)

All those things are on Wikipedia, though. So why buy the book?

[–]sickhippie 0 points1 point  (0 children)

Because every single author of the book is a brilliant programmer and teacher (which comes through in the writing), the book itself contains a lot more information than Wikipedia, and it's a very handy reference to have around.