如何将我的C#Windows窗体应用程序项目划分为不同的层? [英] How Can I Divide My C# Windows Forms Application Project Into Different Layers?

查看:76
本文介绍了如何将我的C#Windows窗体应用程序项目划分为不同的层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#中创建了学生管理系统项目,其中包含windows表单,每个表单都有自己的数据库连接和数据库查询等。我想将我的项目划分为不同的层,业务lyr,表示lyer,数据逻辑lyr我如何能够这样做请指导我。我希望sql相关数据包含sql类,其他类包含其他数据。我可以将我的项目划分为不同的类,分层。

谢谢advance

I have created student management system project in c#,which contain windows forms,and every form have their own database connection and database queries etc.I want to divide my project into different layers,business lyr,presentation lyer,data logic lyr etc.How can i do this please guide me.I want that sql related data contains sql class and other class contains other data.how can i divide my project into different classes,into layers.
Thanks in advance

推荐答案

如果你已经编写了它,那将会很困难 - 从一个新的解决方案开始,并且添加三个更容易项目:PL,BL和DL,然后设计它们之间的接口。



从完成的项目开始尝试分离它就像尝试重建一个平房,一个3层楼的房子,同样的楼层大小,而你仍然住在它! :笑:

如果你开始在花园的另一端建造新建筑,并且只有在完工时拆除平房,那就容易多了。
If you've already written it, it's going to be difficult - it's a lot easier to start from a clean slate with a new solution, and add three projects: PL, BL, and DL and then to design the interfaces between them.

Starting with a "finished item" and trying to separate it is like trying to rebuild a bungalow into a 3 story house with the same floor size while you are still living in it! :laugh:
It's a lot easier if you start constructing the new building at the other end of the garden and only demolish the bungalow when it's finished.


夫妇有用的链接 -

了解C#中的3层架构 [ ^ ]

演练:创建N层数据应用程序 [< a href =https://msdn.microsoft.com/en-us/library/bb384570.aspxtarget =_ blanktitle =New Window> ^ ]



如前所述,这些在新解决方案中效果最好(不是已经创建的解决方案)。
Couple of useful links -
Understand 3- Tier Architecture in C#[^]
Walkthrough: Creating an N-Tier Data Application[^]

As mentioned earlier, these will work best in a new solution (not in one that has already been created).


在自己的项目中创建所需的层适当地移动代码一个部分。如果您的代码结构不合理,那么您可能需要一些中间步骤...



一个这样的步骤可能是先将一些移动的代码公开,以便您不要不必一次改变一切。然后当调用者更新为使用图层界面时,使实现内部。



使用源修订控制并经常进行签入。测试了很多。做小步骤。做单元测试。



对于没有经过适当单元测试的复杂项目,如果代码设计得不够好,可能很难在不破坏代码的情况下更新代码。
Create desired layers in their own project and move code as appropriate one part a a time. If your code is not well structured, then you might some some intermediate steps...

One such step might be to make some moved code public first so that you don't have to change every thing at once. Then when caller is updated to use layer interface make the implementation internal.

Use source revision control and do checkins often. Test a lot. Do small steps. Do unit testing.

For complex project without proper unit testing, it might be hard to update code without breaking it too much if the code is not well enough designed.


这篇关于如何将我的C#Windows窗体应用程序项目划分为不同的层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆