To be able to write high-quality code, you need to learn some programming methodologies, including object orientation (we can think of it as a design philosophy), design principles, design patterns, programming specifications, refactoring techniques, and so on. So today I’m going to briefly introduce these concepts and talk about how they relate to each other.

object-oriented

Today, there are three major paradigms or styles of programming: procedural, object-oriented, and functional programming. Object-oriented programming is the most mainstream of these. Most of the popular programming languages today are object-oriented. Most projects are also developed in an object-oriented programming style. Because of its rich characteristics (encapsulation, abstraction, inheritance, polymorphism), object-oriented programming can realize a lot of complex design ideas, is the basis of many design principles, design pattern coding implementation.

This piece of knowledge
Here are 7 big things you need to know.

1, object-oriented four features: encapsulation, abstraction, inheritance, polymorphism

2. The difference and relation between object-oriented programming and procedural programming

3, object-oriented analysis, object-oriented design, object-oriented programming

4. The differences between interfaces and abstract classes and their application scenarios


Design ideas based on interface rather than implementation programming

6. The design idea of multi-purpose combination and less inheritance

7. Process-oriented anemia model and object-oriented hyperemia model

Design principles

Design principles are lessons learned to guide our code design. One of the great things about design principles is that they sound abstract, vaguely defined, and can be interpreted differently by different people. Therefore, simply memorizing the definition is of little significance to the improvement of programming and design ability. For each design principle, we need to know why it was designed, what programming problems it solves, and what application scenarios it has. Only then can we apply these principles flexibly and appropriately in our projects.

For this part of the article, you will need to thoroughly understand and master how to apply the following common design principles.

· SOLID Principle -SRP single responsibility principle

· SOLID principle -OCP open and close principle

· SOLID principle -LSP replacement principle

· SOLID principle -ISP interface isolation principle

· SOLID principle -DIP dependence inversion principle

· DRY principle, KISS principle, YAGNI Principle and LOD principle

Design patterns

Design pattern is a set of solutions or design ideas summed up for some design problems often encountered in software development. Most design patterns address the extensibility of code. Design patterns are less abstract than design principles, and most of them are not hard to understand, and the code implementation is not complicated. The difficulty of learning this part is to understand what problems they can solve, master the typical application scenarios, and know not to over-apply.

There are 23 classic design patterns. They can be divided into three main categories: creative, structural, and behavioral.

Create a type

Common examples are: singleton pattern, factory pattern (factory method and abstract factory), builder pattern.

Less commonly used are: prototype patterns.

structured

Commonly used are: proxy mode, bridge mode, decorator mode, adapter mode.

Not commonly used are: facade mode, combination mode, enjoy yuan mode.

Behavior type

Common examples are observer pattern, template pattern, policy pattern, responsibility chain pattern, iterator pattern, and state pattern.

Less commonly used are: visitor mode, memo mode, command mode, interpreter mode, mediation mode.

Programming specification

Programming specifications are primarily concerned with code readability. Coding specifications are more specific and focus on code details than design principles and patterns. Even if you may not be familiar with design principles and patterns, you should at least understand basic coding conventions, such as how to name variables, classes, and functions, how to write code comments, and how to keep functions long and parameters small.


For coding specifications, consider that many books have been written about them (refactoring, Code Code, Clean Code, etc.). Moreover, each coding specification is very simple, very specific and memory-oriented, so you just have to follow it. It’s not like design principles, which require a lot of personal understanding and thought.



Code refactoring

In software development, there is no one-size-fits-all design as long as the software is constantly iterating. With the change of requirements, code piling up, the original design is bound to have such and such problems. To address these issues, we need to refactor the code. Refactoring is a very important part of software development. Continuous refactoring is a great way to keep code quality from deteriorating to the point where it can rot beyond redemption.


The tools for refactoring are the object-oriented design ideas, design principles, design patterns, and coding specifications outlined earlier. In fact, one of the most important applications of design ideas, design principles, and design patterns is in refactoring. As we mentioned earlier, while design patterns can improve code extensibility, they can also increase code complexity and affect code readability when used inappropriately. In the early stages of development, we should not overdesign and apply complex design patterns unless we absolutely have to. Instead, when something goes wrong with the code, we refactor it, applying principles and patterns to the problem. This can effectively avoid over-design in the early stage.


Here are a few things you should know about refactoring:

The purpose of reconstruction (why), object (what), time (when), method (how);

Technical means of ensuring error-free refactoring: unit testing and testability of code;

There are two types of refactoring at different scales: large refactoring (large-scale high-level) and small refactoring (small-scale low-level).


Hopefully, by the end of this part, you will not only have mastered some refactoring techniques and routines, but more importantly, build a sense of continuous refactoring and integrate it into your daily development as part of your development.

The link between the five

Because of its rich characteristics (encapsulation, abstraction, inheritance, polymorphism), object-oriented programming can realize a lot of complex design ideas, is the basis of many design principles, design patterns and other coding implementation.



Design principles are a summary of the experiences that guide our code design, and can be useful for guiding whether or not certain design patterns should be applied in certain scenarios. For example, the “open close principle” is the guiding principle for many design patterns (policies, templates, and so on).



Design pattern is a set of solutions or design ideas summed up for some design problems often encountered in software development. The main purpose of applying design patterns is to improve the extensibility of code. In terms of abstraction, design principles are more abstract than design patterns. Design patterns are more concrete and executable. Programming specifications are primarily concerned with code readability.



Compared with design principles and design patterns, coding specifications are more specific, more focused on code details and more practical. Continuous small refactoring relies on the theoretical basis of programming specifications.



Refactoring, as an effective means to keep code quality from deteriorating, takes advantage of object-oriented, design principles, design patterns and coding specifications.

In fact, object orientation, design principles, design patterns, programming specifications, and code refactoring are all methodologies for maintaining or improving code quality, essentially in the service of writing high-quality code. When we go back to the source and see the essence of this, it becomes clear how to do a lot of things and how to choose a lot of choices. For example, if the design pattern should be used in a particular scenario, it can be used to improve the extensibility of the code. Whether or not to refactor depends on whether the code has readable, maintainable issues, etc.



Today’s knowledge is introduced here, do you understand? I also have some front-end learning materials here. If you need them, you can leave a message to me and I will share it with you for free. There are also some VIP learning videos of some institutions worth 2980 yuan.



Source: WEB Bright Top (
web.xingruanedu.com/)


Pay attention to the wechat official account of WEB Bright Top for more front-end learning materials