+ 1
What are design patterns, is it generic or language specific?
what is the use of having design patterns, anyone can share the inputs with examples if possible
2 ответов
+ 3
Design patterns are common ways to solve some problem. They are by design language agnostic. They provide a way for developers to communicate to each other what their code is doing at a high level without going into detail. They also prevent you from recreating a solution to a solved problem.
One example is the observer pattern which allows you to listen for some event or action to happen and act on it. JavaScript is great at this and uses it heavily.
function myCallback() {
console.log('button clicked');
}
const button = document.getElementById('#myButton');
button.addEventListener(myCallback);
+ 2
Design patterns are not language specific.
They are like high level 'recipes' to use in commonly found situations.
When you recognise the need for a pattern you can look up on how to design the solution properly.and avoid common errors.
Also they have a name, so programmers can communicate like ' you should use a singleton pattern there..'