0

I am currently bussy with my Class Diagram.

My project has some classes (example: User.cs, Friend.cs, Message.cs).

And I have also some .aspx and .ascx (web user control) files which also have classes, for example: ShowFriends.ascx has a ShowFriends.ascx.cs-class.

What I would like to know is: Do I need to take create a class in my class diagram for the ShowFriends.ascx.cs-class? Or is that not allowed because it's a part of a .ascx file? If I don't do it, I will miss lots of things in my class diagram.

If it is allowed: How I can seperate the Friend.cs with the ShowFriends.ascx.cs file in the class diagram? Because the Friend.cs file has only some attributes in it, and the ShowFriends.ascx.cs file has methods like ShowFriends(). And if I create a relation between User and and Friend.cs and ShowFriends.ascx.cs it looks very weird.

For me it's more logical to have one class called Friend.cs or something with all attributes and methods in it (methods Like ShowFriends()), but I dont have that, because I need to create some methods in the .ascx.cs file because of using Request.QueryString["Username"].

Thanks in advance!

Swag
  • 2,090
  • 9
  • 33
  • 63

1 Answers1

1

The best practice is to define all your classes in a separate file. If you're concerned about accessing the Request object you can still do that outside of the .ascx-files.

As long as your project references System.Web you can access it like this:

 string user = HttpContext.Current.Request["Username"];

I wouldn't put the ascx.cs files inside the class diagram. In the class diagram you want to define your domain model, not your UI.

Kenneth
  • 28,294
  • 6
  • 61
  • 84
  • Thanks for your answer, so u recommend me to transer my ShowFriends() method from the web user control file to my normal Friend class? But if I do that then I can't access the repeater which is in my ShowFriends.ascx file... – Swag May 09 '13 at 19:19
  • If you're accessing the repeater inside that method, you should leave it in there. What I meant with that is that you don't really need that method in your class diagram. Overall you should try to have as little code as possible in the .ascx and push any logic into other classes that do form part of your class-diagram – Kenneth May 09 '13 at 19:21
  • Thank you very much. Should it not be weird when I don't have ShowFriends() or AddFriend() in my class diagram? – Swag May 09 '13 at 19:23
  • Not really, since that's basically view logic. That logic should be simple enough so you don't need to visualize it for refactoring and so on. All in all, for separation concerns asp.net web forms is not the best option. If you're really interested in a clean separation of concerns, you might want to take a look at ASP.NET MVC – Kenneth May 09 '13 at 19:25