zoukankan      html  css  js  c++  java
  • dispather patterns

    dispatcher

    https://hub.packtpub.com/dispatchers-and-routers/

    分发器,接收消息,分发到对应的模块进行处理。

    Dispatchers

    In the real world, dispatchers are the communication coordinators that are responsible for receiving and passing messages. For the emergency services (for example, in U.S. – 911), the dispatchers are the people responsible for taking in the call, and passing on the message to the other departments (medical, police, fire station, or others). The dispatcher coordinates the route and activities of all these departments, to make sure that the right help reaches the destination as early as possible.

    优点:

    集中控制

    应用切分

    减少相互依赖

    Dispatcher as a pattern

    Dispatcher is a well-recognized and used pattern in the Java world. Dispatchers are used to control the flow of execution. Based on the dispatching policy, dispatchers will route the incoming message or request to the business process. Dispatchers as a pattern provide the following advantages:

    • Centralized control: Dispatchers provide a central place from where various messages/requests are dispatched. The word “centralized” means code is re-used, leading to improved maintainability and reduced duplication of code.
    • Application partitioning: There is a clear separation between the business logic and display logic. There is no need to intermingle business logic with the display logic.
    • Reduced inter-dependencies: Separation of the display logic from the business logic means there are reduced inter-dependencies between the two. Reduced inter-dependencies mean less contention on the same resources, leading to a scalable model.

    URL dispatcher

    django URL:

    https://docs.djangoproject.com/en/4.0/topics/http/urls/

    ROUTER VS DISPATCHER

    https://stackoverflow.com/questions/11700603/what-is-the-difference-between-url-router-and-dispatcher

    ROUTER来源于网络的路由器,本身是一个设备,在这里是一个名词,具有提供目标方向的功能。

    DISPATCHER为分发器的意思,重点强调分发的能力,利用ROUTER,实现分发功能。

    The Concepts

    Routing

    This is kinda like asking for directions at a gas station or convenience store. You're going through town and you need to figure out how to get to the nearest hotel. You go in and ask the attendant and they point you off in the correct direction, or at least you hope the directions are correct. Routing is exactly this. A request comes in for a resource, the Router provides the directions necessary for the request to reach the correct resource.

    In most major frameworks you're going to be routing a specific request URL to an object and method that will be invoked to complete the request. Often times you'll see the Router also parsing out dynamic arguments from the URL. For example, if you accessed users via /users/1234 where 1234 is the user ID the Router would parse out the ID portion and provide this as part of the directions to the resource.

    Dispatching

    Dispatching uses the information from the Routing step to actually generate the resource. If the Routing step is asking for directions then Dispatching is the actual process of following those directions. Dispatching knows exactly what to create and the steps needed to generate the resource, but only after getting the directions from the Router.

    $router = new Router();
    $router->get('foo', function() { echo "GET foo\n"; });
    $router->post('bar', function() { echo "POST bar\n"; });
    
    $dispatcher = new Dispatcher($router);
    
    $dispatcher->handle(new Request('GET', 'foo'));
    $dispatcher->handle(new Request('POST', 'bar'));
    $dispatcher->handle(new Request('GET', 'qux'));

    REDUX STORE DISPATCHER

    https://www.esri.com/arcgis-blog/products/js-api-arcgis/3d-gis/react-redux-building-modern-web-apps-with-the-arcgis-js-api/

    DISPATCHER 分发 action 到 store中的 对应的 reduce, 执行修改state

    Front Controller Pattern

    https://www.tutorialspoint.com/design_pattern/front_controller_pattern.htm

    前端控制器,接受请求

    分发器 根据请求类型,将请求分发到 对应的 模块处理

    例如 手机请求, 响应手机页面; 桌面请求响应 桌面页面。

    The front controller design pattern is used to provide a centralized request handling mechanism so that all requests will be handled by a single handler. This handler can do the authentication/ authorization/ logging or tracking of request and then pass the requests to corresponding handlers. Following are the entities of this type of design pattern.

    • Front Controller - Single handler for all kinds of requests coming to the application (either web based/ desktop based).

    • Dispatcher - Front Controller may use a dispatcher object which can dispatch the request to corresponding specific handler.

    • View - Views are the object for which the requests are made.

    Implementation

    We are going to create a FrontController and Dispatcher to act as Front Controller and Dispatcher correspondingly. HomeView and StudentView represent various views for which requests can come to front controller.

    FrontControllerPatternDemo, our demo class, will use FrontController to demonstrate Front Controller Design Pattern.

    Front Controller Pattern UML Diagram

    https://docs.oracle.com/cd/E19929-01/816-4337/03_design_issues.html

    Typically, the Front Controller coordinates user navigation, using the Dispatcher subpattern for this purpose. As shown in FIGURE 3-2, the Front Controller processes a request. Perhaps the user might want to check out items in a shopping cart of an e-commerce application.

     FIGURE 3-2 Dispatching as a Function of a Front Controller

    Figure showing dispatcher communication with Front Controller to route user requests to appropriate view.[ D ]

    COMMAND DISPATCHER PATTERN

    极致解耦模式:

    CLIENT 注册 command handler 到 command dispatcher

    INVOKER 构造 command, 调用 command dispatcher

    command dispatcher 查找 command handler, 根据command 的key

    command dispatcher 分发 命令, 执行 command 对应 command handler的 handle command方法

    command handler 调用receiver的action执行真正的业务逻辑。

    https://hillside.net/plop/plop2001/accepted_submissions/PLoP2001/bdupireandebfernandez0/PLoP2001_bdupireandebfernandez0_1.pdf

    UML reference

    https://www.lucidchart.com/pages/uml-class-diagram#section_2

    https://courses.cs.washington.edu/courses/cse403/16au/lectures/L07.pdf

    https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-class-diagram-tutorial/

    出处:http://www.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    Android OpenGL(2)
    Bootloader:BareBox
    Android OpenGL(1)
    Android脚本环境
    Android用户界面开发:事件处理
    S5PV210按键控制LED
    S5PV210控制蜂鸣器
    Windows Vista/Windows 7上安装wince5.0/6.0及SDK模拟器
    Makefile
    每日英语:Apps Reorder the Job Landscape
  • 原文地址:https://www.cnblogs.com/lightsong/p/15724340.html
Copyright © 2011-2022 走看看