dousa2794 2011-05-25 00:43
浏览 52
已采纳

服务应该像控制器吗?

I've done a fair amount of (web)development in the usual MVC way of thinking and it served me well I think.

However, I now have to split my application in a way that my front-end has to access the server-side functions as services.

Since I'm the one creating the services, I thought I could think of services as controllers which would, in turn, call the functions in my model.

Is that a good way to do it?

Thank you

P.S.: The server side techonology in question is PHP and the client-side is Adobe Flex (ActionScript).

  • 写回答

2条回答 默认 最新

  • dongtuo3370 2011-05-25 01:17
    关注

    There are a ton of different approaches, and I can't say any of them are wrong. I'm wondering what is your current approach; and what the limitation are that make you want to change it.

    The approach you seem to be suggesting is to create a facade that stands between the model (AKA PHP Code that does the 'heavy backend lifting') and the view (AKA the Flex Front end). I don't have an inherit problem with that; especially if you already have a backend implemented that contains all the heavy lifting/business logic. I would consider this facade layer a service layer and would consider it part of the model; not part of the controller.

    When trying to create an Model-View-Controller-Services (MVCS) architecture between Flex and some backend; I generally do it this way:

    The views are implemented as Flex Components.

    The Controller is implemented as an ActionScript class. From my perspective, the controller's main purpose is to shuffle requests to the server and data back to the views.

    The Service Layer is implemented on the server; PHP in your case. It may be that you have a parallel service class in Flex for each services you have on the server side.

    The Model Layer has classes to perform relevant business logic; to validate data to save it to a database to retrieve it from a database, and whatever other business logic you need. Often as part of the Model I have Value Object classes. Value Object classes are often paralleled in ActionScript and are used for transfer of data between the server side service and the client side controller.

    So, it kind of works like this:

    1. The user interacts with the view
    2. The view dispatches an event to the controller
    3. The controller makes a remote call to a service on the server
    4. The service calls the model to get data
    5. The Model gets the request, performs appropriate actions, creates a value object--or array of value objects--and returns that to the service
    6. The Service returns the results to the client side controller
    7. The Controller does something to update the views

    There are a lot of frameworks out there to help this process, especially for "encapsulated" communication between layers of the application.

    In many cases; the line between "what should go in the model / what should go in the view" is blurred. When we're developing Flex (or AJAX or Silverlight or any smart client) applications, often we want to have smart views; so some business logic may get implemented as part of the view. That's fine; we have to balance the functionality of the app with an "ideal" abstraction case.

    Your question was a bit broad, but I hope this helps. I, personally, prefer to be practical about my application architecture. Sometimes my service classes perform business logic, such as data parsing. It depends on the app and it's goals and the client and the time frame.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下