应用程序和数据库之间的面向对象设计? [英] Object Oriented Design between application and database?

查看:83
本文介绍了应用程序和数据库之间的面向对象设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


从上周开始,我一直在研究适当的面向对象设计.我已经阅读了有关SOLID原理和一些使用这些原理的设计模式的信息.经过一周的阅读和练习,我对这些原理有了基本的了解.在学习过程中,我不禁感到这些SOLID原理和设计模式无法解决软件设计中的一个非常重要的问题:数据库交互.
与数据库的交互对于几乎所有应用程序都很重要.但是什么时候我应该在应用程序设计中加入一些业务逻辑,何时在数据库中进行处理呢?我一直在阅读有关代码的可重用性的信息,但是当我使用存储过程进行一些数学运算时,我不能指望该SP在其他应用程序(可能使用另一个数据库)中可重用.但是,将某些逻辑放入数据库中可能确实可以提高应用程序的性能.
举个例子,我的公司过去曾在特定日期和代码中为特定客户计算特定产品的价格.这花了几秒钟.将计算结果放入数据库时​​,仅需几毫秒.
每当我在SQL2008中查看SP时,都不会看到任何SOLID原理.而且,如果我愿意的话,我肯定会发疯,因为必须找到大约10个函数和SP才能在SQL中进行单个计算并不像在Visual Studio中那样容易.

因此,我想知道的是,是否有任何SOLID数据库原则和SOLID应用程序到数据库原则可以最大程度地利用常规SOLID原则.
我不需要详细的解释.对于解决此问题的文章,书籍和/或网站的一些引用就足够了.但是现在我不知道在哪里看:)
谢谢.

Hi,
Since last week I have been looking into proper object oriented design. I have read about the SOLID principles and some Design Patterns which use these principles. After a week of reading and practicing I feel I have a basic understanding of the principles. As I am progressing in my study I cannot help but feel these SOLID principles and Design Patterns do not address a very important issue in software design: database interaction.
Interaction with a database is important for almost any application. But when would I put some business logic into my application design and when would I handle it in my database? I have been reading about reusability of code, but when I use a stored procedure to do some math I cannot count on that SP to be reusable in another application (that might use another database). Putting certain logic in a database might really speed up performance of the application though.
To give an example, my company used to calculate prices for a certain product for a certain customer on a certain date and a certain amount in code. This took several seconds. When putting the calculation in the database it took only a few milliseconds.
Whenever I look at SP''s in SQL2008 I do not see any of the SOLID principles though. And if I would I would most certainly go crazy because having to find around 10 functions and SP''s to do a single calculation in SQL is not as easy as in Visual Studio.

So what I would like to know is if there are any SOLID database principles and SOLID application-to-database principles to make maximum use of the regular SOLID principles.
I do not need detailed explanations. Some references to articles, books and/or websites that address this issue is enough. But right now I would not know where to look :)
Thanks.

推荐答案

要首先能够有效地使用数据库计算,您必须具有包含所有相关信息的规范化数据库.从那里开始创建存储过程以进行计算.这将采用所需的参数,并且仅返回所需的结果,这将减少您的网络流量.首先在SQL中测试您的SP.

在Visual Studio中,您所需要做的就是创建一个Linq to SQL并连接到sp,然后使用sp的结果.

为了在另一个应用程序中使用,我怀疑您将对某些零件使用另一个分贝,然后要求从第一个分贝计算价格.您需要做的就是创建第二个linq文件.
To be able to use database calculations effectively first you must have a normalised database with all the relevant information. From there progress to create a stored procedure to do your calculations. this will take the required parameters and return only the required results, which will reduce your network traffic. Test your SP in SQL first.

From visual studio all you will need to do is to create a Linq to SQL and connect to the sp and use the results of the sp.

For use in another application I suspect that you will be using another db for some of the parts and then require the price calculation from the first db. All you will need to do here will be to create a second linq file.


这篇关于应用程序和数据库之间的面向对象设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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