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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line