Componentizing complex functionality in an MVC web app
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 page开发者_如何转开发s 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.
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.
精彩评论