-1

Let's say we have a website requirement to allow User functionality. Simple!

We create the UserModel, UserController and UserView. Works perfectly.

However, let's assume that User has a many-to-one relational table connected to it titled Child which also has its own MVC components: ChildModel, ChildController, ChildView. Now if we had a requirement to create a CSV file for download containing a few details from the User and a few details from its Child, how would we go about designing this requirement?

"DownloadCSV" could essentially have its own CRUD methods, it's own Controller, it's own View but its Model is based on the details from other tables, so should it have its own Controller, View, Model(/DB View) or should it just be another method besides CRUD in User or Child controller?

  • 1
    Build the design to meet the requirements, not the other way around. – RibaldEddie Jan 22 '14 at 17:08
  • 3
    Questions like this scare me, just because I have a hammer, doesn't make every problem a nail. Too many times I see developers, especially junior ones, try to make the problem fit their toolset. – cdkMoose Jan 22 '14 at 18:08
  • Design patterns are like tools, they either fit your requirements or they don't. If not, the pattern should change not the requirements. – cdkMoose Jan 23 '14 at 17:05
0

In terms of a web application (not sure if that is the case here, but the concept is the same I think) On ChildController there is typically an "index" method that is used to render a page listing all children.

I view this "DownloadCSV" functionality as very similar to that, except that the server is sending a CSV file as the HTTP response rather than an HTML page. Therefore, it seems to me that this would be appropriate as another method of ChildController.

  • However, the CSV file will list data from both User AND Child. So if that's the case then why is it in the Child index and not the Parent index? – ThreaT Jan 22 '14 at 15:29
  • 1
    @ThreaT I'm making an assumption that the data is more "child-centric" rather than "user-centric". Here is what I am assuming: Each record has some columns that come from both Child and User data. If a user has 2 children, then there will be 2 corresponding records in the CSV data, and the User columns will have duplicate values. If a user does not have any children, then it will not be in the CSV data. To me, this sounds like "give me a list of all children, and oh by the way please include which user they belong to." – Dr. Wily's Apprentice Jan 22 '14 at 15:39
0

Maybe you shouldn't try to force it to fit MVC. Many times, reporting and data dump tasks don't fit the framework used to build the interactive applications which create and manipulate the data. And that is not a bad thing. It is quite possible that you could generate this data download using a separate class/task that could use the same stored procedures internally for consistency, but is driven by the reporting needs which are different from needs for the presentation/control of data in the application.

  • Maybe not even a controller. Depending on your architecture, make a direct call to a worker/service that returns the raw data based on a simple set of parameters. Csv dumps can actually be pretty straight-forward and don't need this framework overhead at all. – cdkMoose Jan 22 '14 at 23:00
  • I'm not suggesting this is the best case at all times, but I also think developers should not force requirements to fit the tools as the question implies. – cdkMoose Jan 23 '14 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.