A design pattern is a general, reusable solution to a problem that comes up repeatedly in software design. It is a template and vocabulary rather than a ready-made piece of code. The best-known catalog is the 1994 book "Design Patterns" by the so-called Gang of Four, which described 23 patterns such as Factory, Observer and Strategy.
Why it matters
Patterns give teams a shared language: saying "this is an observer" conveys structure and intent in one phrase. They capture solutions that have worked in practice and can guide how to separate responsibilities. Patterns can also be overused, adding indirection where a simple function would do, and some are workarounds for limits of specific languages.
Example
The Observer pattern lets objects subscribe to events from another object.
class Monitor {
subs = [];
subscribe(fn) { this.subs.push(fn); }
notify(status) { this.subs.forEach(fn => fn(status)); }
}
const m = new Monitor();
m.subscribe(s => console.log("alert:", s));
m.notify("down");
Common mistakes
- Applying a pattern because it is familiar rather than because the problem needs it.
- Copying a pattern's textbook form without adapting it to the language in use.
- Confusing patterns with architectures, which operate at a larger scale.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.