Introduction:Reliable Design Patterns are the cornerstone of maintenance software. If you have been in a technical interview, you may be asked about design patterns. In the following guide, we will learn some design patterns that can be used today.
What is the design model?
Simply put, the design pattern is a software solution for reusing specific types of problems. These problems are often encountered during software development. Through years of practice, experts have summarized some methods for some similar issues. These methods are encapsulated into a design model, so:
A pattern is a proven solution for solving software development problems.
Patterns are scalable because they are often structured and you need to follow certain rules.
Similar problems can be reused.
In the next tutorial, we will provide some examples of the design pattern.
Types of design patterns
In software development, design patterns are generally divided into several categories. In this tutorial, we will focus on the following three types:
1. The Creation Mode focuses on building objects or classes. Object creation sounds simple (in some cases), but large applications need to control the object creation process.
2. The structural design model focuses on the relationship between management objects so that applications can be scaled. The key aspect of the structural model is to ensure that some changes in the application do not affect other parts.
3. behavior patterns focus on communication between objects
You may still think that there is a problem after reading the description of these profiles. This is normal. Once we have read the in-depth introduction of these models, the problem will become clearer, so let's take a look.
Note:
When we read the design pattern, you often mention classes and objects. This is confusing because JavaScript does not have a true "class" structure. A more appropriate term is "data type ".
Data Types in JavaScript:
JavaScript is an object-oriented language. An object inherits from other objects. This concept is known for prototype inheritance. A data type can be created through constructors, just like:
- function Person(config) {
- this.name = config.name;
- this.age = config.age;
- }
-
- Person.prototype.getAge = function() {
- return this.age;
- };
-
- var tilo = new Person({name:"Tilo", age:23 });
- console.log(tilo.getAge());
When defining a method in the Person data type, pay attention to the use of prototype. Because multiple Person objects reference the same prototype, getAge () is allowed () this method can be shared by all Person-type instances. Instead of redefining each instance, any data type inherited from Person can access the getAge () method.