在 MVC Web 应用程序中组件化复杂的功能

发布于 2024-09-04 16:47:36 字数 627 浏览 7 评论 0原文

这是关于 MVC Web 应用程序架构以及如何扩展它的问题 处理适度复杂的功能单元的组件化。

我有一个 MVC 风格的网络应用程序,带有面向客户的信用卡收费页面。

我被要求允许管理员也输入信用卡付款, 当信用卡被通过电话收取时。

网站上面向客户的信用卡收费部分目前是 它有自己的控制器,大约有 3 个页面和一个登录名。那个控制器 负责:

  • 客户登录 凭证认证
  • 信用卡数据采集
  • 调用图书馆做实际收费。
  • 将结果报告给用户。

我想将卡片数据收集页面提取到一个组件中 某种形式,以便我可以轻松地在应用程序的管理端重用代码。

现在我的组件仅限于 PHP 风格的单个“视图”页面 嵌入 Perl 代码。

这是一个用 Perl 编写的简单的自定义 MVC 框架。现在,控制器 直接从框架调用来服务 Web 请求。我的想法是 允许从其他控制器调用控制器,以便我可以组件化 更复杂的功能。

为了简单起见,我认为我更喜欢组合而不是继承,尽管它会 需要编写一堆传递方法(动作)。作为 Perl,我可以 理论上做多重继承。

我想知道是否有其他 MVC Web 框架经验的人可以发表评论 关于此类事情通常是如何完成的。

谢谢。

This is question about MVC web-app architecture, and how it can be extended
to handle componentizing moderately complex units of functionality.

I have an MVC style web-app with a customer facing credit card charge page.

I've been asked to allow the admins to enter credit card payments as well,
for times when credit cards are taken over the phone.

The customer facing credit card charge section of the website is currently
it's own controller, with approximately 3 pages and a login. That controller
is responsible for:

  • Customer login credential authentication
  • Credit card data collection
  • Calling a library to do the actual charge.
  • reporting the results to the user.

I would like to extract the card data collection pages into a component of
some kind so that I can easily reuse the code on the admin side of the app.

Right now my components are limited to single "view" pages with PHP style
embedded Perl code.

This is a simple, custom MVC framework written in Perl. Right now, controllers
are called directly from the framework to service web requests. My idea is to
allow controllers to be called from other controllers, so that I can componentize
more complex functionality.

For simplicity I think I prefer composition over inheritance, even though it will
require writing a bunch of pass-through methods (actions). Being Perl, I could in
theory do multiple inheritance.

I'm wondering if anyone with experience in other MVC web frameworks can comment
on how this sort of thing is usually done.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凹づ凸ル 2024-09-11 16:47:36

创建一个包含所有 cc 特定功能的组件(类?),并通过适当的方法/函数公开它。

使用组合为您的控制器(面向客户和管理员)提供 cc 组件的实例,并调用适当的方法来实现需要发生的事情。

我已经处理过类似的事情很多次了,我绝对更喜欢让我的“控制器”(或任何其他直接依赖于第三方库的代码)尽可能“愚蠢”,并且像你说的那样 - 传递任何东西这需要特定于您的应用程序的功能。这使我的代码易于测试,这也是我目前大部分设计的动力。

我希望我们谈论的是同样的事情,MVC 可以应用于许多不同的级别,有时会让人感到困惑。

Create a component (class?) which wraps all the cc specific functionality, and expose it through appropriate methods/functions.

Use composition to provide your controllers, both customer and admin facing, an instance of the cc component, and have both call the appropriate methods to achieve what needs to happen.

I have dealt with something similar many times, and I absolutely prefer keeping my "controllers" (or any other code that depends directly on third party libraries for that matter) as "stupid" as possible, and do like you said - pass through anything that calls for functionality that's specific to your app. This keeps my code easy to test, which is what drives most of my design these days.

I hope we're talking about the same things, MVC can be applied at so many different levels it sometimes gets confusing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文