In this tutorial: http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part4-cs
This instruction: "In the same file, add the following
MovieDBContext
class:" is followed by the code to add that class.
I was taught that each class should be in it's own file. For the tutorial of course I will follow the instructions. I'm wondering about doing it for real. Is it normal practice to have more than one class in a file in situations like the one in the tutorial?
In terms of performance, there is no difference, it's exactly the same. But for maintainability and easy of use, it's often considered best practiceto place each class in it's own file.
The movies tutorial is a getting started tutorial and aimed at beginners which is why the context is created in the same file. In a real application, you would have the context in it's own .cs file and the each model in it's own file as well.
I try to keep each class in it's own file. There are a few exceptions of course,but in general I like to keep each class in it's own file.
Dan Bracuk
Contributor
3970 Points
1096 Posts
Would You Do It Like This?
Apr 09, 2012 01:30 AM|LINK
In this tutorial: http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part4-cs
This instruction: "In the same file, add the following
class:" is followed by the code to add that class.I was taught that each class should be in it's own file. For the tutorial of course I will follow the instructions. I'm wondering about doing it for real. Is it normal practice to have more than one class in a file in situations like the one in the tutorial?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Would You Do It Like This?
Apr 09, 2012 01:41 AM|LINK
In terms of performance, there is no difference, it's exactly the same. But for maintainability and easy of use, it's often considered best practiceto place each class in it's own file.
The movies tutorial is a getting started tutorial and aimed at beginners which is why the context is created in the same file. In a real application, you would have the context in it's own .cs file and the each model in it's own file as well.
I try to keep each class in it's own file. There are a few exceptions of course,but in general I like to keep each class in it's own file.
Blog | Twitter : @Hattan