开发者

What special considerations should I make when creating an object model that will be consumed by a desktop application and web site?

开发者 https://www.devze.com 2023-01-13 02:13 出处:网络
I\'m writing a tool in C#.Net that will be used to generate Catalogs of content which users can browse. Initially I am creating a WinForms based interface, but in the future I\'d like to be able to cr

I'm writing a tool in C#.Net that will be used to generate Catalogs of content which users can browse. Initially I am creating a WinForms based interface, but in the future I'd like to be able to create a web based interface as well. So I've been careful to genera开发者_高级运维lize the interface to a Catalog so that it does not depend on a specific UI.

My only experience with web development has been creating my own HTML website back in the early 90's, and I've done a little ASP (not ASP.NET). Now with ASP.NET it seems that I should be able to leverage my existing C#.Net object model, to create a web base interface. But I really hasn't done anything with ASP.NET beyond a simple hello world example.

Are there any special considerations I should make in designing my object model so that later I can create a web interface to it?


Here are few things to follow:

  1. You should package your object model is separate project (that you need to do anyway to share it among different projects) and make sure that you do not add specific references to it (for example, don't add System.Web, WinForms, WPF etc) - this will automatically avoid any unwanted dependencies.
  2. Try to have your classes as lean as possible. Avoid classes that track change states etc - in web scenario, tracking state over multiple requests is expensive. So it's best to have to your objects carry data only.
  3. Consider the possibility that your objects may need to be serialized and/or passed over a wire. For example, a middle ware services serving both windows & web client. Or web page storing the object in the view-state.


There really shouldn't be that big a difference.

Be careful about placing too much “intelligence” in your entity classes. That’s a pattern I’ve seen often in Windows apps. Don't make references to controls that are specific to Windows Forms development in the parts of your project that you want to reuse for the web application.

Repository patterns work well with both Windows and Web applications, because you often want to optimize the web apps differently for performance with multiple users.


Your requirement can be handled with a multi-tier architecture:

http://en.wikipedia.org/wiki/Multitier_architecture

0

精彩评论

暂无评论...
验证码 换一张
取 消