MVC Architecture + Observer Mode of Unity Engineer Interview Knowledge Points

The so-called design pattern is generally understood as a routine to solve fixed problems. Speaking of the observer pattern, we have to mention the most commonly used implementation logic in client framework design: MVC architecture + observer pattern.

M, V, and C in the MVC architecture are the abbreviations for model, view, and control, respectively.

model: model, processing data logic part

view: interface, processing data display part

control: The controller, the communication bridge between the model and the interface, is responsible for reading data from the view, controlling user input, and sending data to the model.

MVC architecture is a typical example of "single responsibility" in object-oriented design principles. It completely separates data processing from interface implementation, greatly reducing code coupling and improving code reusability. However, this creates a problem, how to effectively solve the problem that once the data of the data layer changes, the corresponding theme interface can be notified in time. Observer pattern as a mechanism for passing messages in MVC architecture makes up for this deficiency.

Observer mode (Observer), also known as subscription-publish mode, defines a "one-to-many" dependency relationship, the main purpose is to solve: when the state of an object changes, it can notify other objects in time. The specific relationship is shown in the figure:

For example, the magazine that publishes the magazine is the subject (publisher), and the customer who subscribes to the magazine is the subscriber. After the customer subscribes to the magazine (subscription subject) from the magazine, the customer will receive the latest news from the magazine. issue magazine. If a customer doesn't want to subscribe anymore, they can cancel and they won't receive the magazine in the future.

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324481835&siteId=291194637