F
F
forven2017-05-12 19:18:53
C++ / C#
forven, 2017-05-12 19:18:53

How to understand/master design patterns?

How to understand design patterns?
I don’t understand them at all, I can’t imagine the principle of their work in my head, how they work and why.
But for a junior vacancy, in most cases, knowledge / understanding of patterns is required.
Maybe I'm a teapot, and programming is not mine?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim, 2017-05-12
@Got_Oxidus

Maybe I'm a teapot, and programming is not mine?

If you got to this topic, then programming is yours, you just approached the problem from the wrong side)
A pattern is a template, a relationship of classes that solves a specific problem.
Read .NET Design Patterns . Most popular patterns are analyzed in detail. (Suitable for Java too)

S
Saboteur, 2017-05-12
@saboteur_kiev

Patterns are terminology for specific sets of solutions.
Imagine that you are solving a problem. Well, for example, in a toy, you program a set of spells that a player can conjure.
At the same time, you make a table (or an array), in one column - how much mana the spell spends, in the other - which classes it is available to, in the third - it hits an enemy, friend or area, in the fourth - some additional condition, for example the spell can only be cast during the day.
Then you want to complicate, add another condition, for example, only during a thunderstorm.
Then you complicate it further, that he can only be conjured if he is not hungry.
Then, after 10 new spells that bring uniqueness and variety to your game, you realize that you have 10=15 columns in the table, in which only one spell is true, and you think how to simplify it all.
Yes, you can switch to beats, but that doesn't change the fact that you keep a list of effects that you only check for once, and you already have several if/case pages.
Then you come up with the idea that you can make a column in which you specify not the next parameter, but call a unique function, inside which you can check various unique effects, and the table is again reduced to 5-6 columns. The solution is - extremely handy for your case - you can easily come up with completely unique condition checks, and it will be easy to integrate them.
Here, you used the executor pattern.
This is not a specific code, and not a language, it's just a variant of solving a problem, not always even an algorithm, but the idea itself.
Actually patterns - these are options, ideas for solving any problems.
Popular patterns can be well and carefully written, with code examples.
More rare ones may have their own name in a small circle of programmers, and not always get into the standards.
But knowing at least popular patterns - you will simply be able to solve popular problems faster, use best practice, step on a rake less often and communicate with colleagues in convenient terminology, which will reduce the time for explanation.

D
Denis Fedorets, 2017-05-14
@fedorez

Read the book from Head First to get started. If there is no more academic reading.

M
MrDywar Pichugin, 2017-05-12
@Dywar

Just learn everything.
In practice, there may be a chance to apply.
A resource for learning - https://metanit.com/sharp/patterns/, it also has a good introduction - why they are, why, where and where.
It will go easier when there is an experience on which what is read can be projected, like - "ah, here it was possible to use it, and here another, damn it, how convenient it is to make such logic."

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question