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 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单