以数据为中心的应用程序模型和面向对象的应用程序模型有什么区别?
什么是以数据为中心的应用程序?与面向对象的应用程序模型有什么区别?
What is a data-centric application and is there any difference with an object-oriented application model ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这两个概念有些正交,以数据为中心的应用程序是数据库发挥关键作用的应用程序,其中的属性数据库可能会影响应用程序中运行的代码路径,并且代码更加通用,并且所有/大多数业务逻辑都是通过数据库关系和约束定义的。 OOP 可用于创建以数据为中心的应用程序。
当人们说 OOP 架构时,他们会想到一些大型的多层架构,它们在代码中实现业务逻辑,并且只存储数据库中的数据。然而,认为面向对象设计必然是一个大型业务逻辑系统的想法是错误的。
假设您必须在两个系统之间实现消息传递。一种方法(尽管是一种不好的方法)是让每个系统将消息写入数据库,而另一个系统经常从数据库中读取消息以获取消息。这将是一种以数据为中心的方法,因为除了读取和写入数据之外,只需要很少的代码。
可以通过让系统相互打开套接字连接并直接发送消息来实现相同的系统。这样就有更多的代码和更少的数据库访问。这是非数据中心方法。其中任何一个都可以使用 OOP 概念来实现。
我工作中的另一个例子是,我们实现了游戏服务器,一种类型的服务器处理多人游戏,因此用户按下按钮,宇宙飞船向其他玩家发射导弹。该服务器不是以数据为中心的,而是基于事件的。另一个服务器存储用户的高分、朋友列表等,该服务器是存储分数和列表的数据库的薄包装。
The two concepts are somewhat orthogonal, a Data Centric Application is one where the database plays a key role, where properties in the database may influence the code paths running in your application and where the code is more generic and all/most business logic is defined through database relations and constraints. OOP can be used to create a data centric application.
Some of the large multi-tier architectures which people think of when they say OOP architecture implement business logic in code and just store the data in the database. However, it would be wrong to think Object Oriented design necessarily has to be a large business logic ridden system.
Say you have to implement message passing between two systems. One way (although a bad way) is to have each of the systems write the messages to the database and the other system read from the database every so often to pick up messages. This would be a data centric approach as there is very little code needed other than reading and writing data.
The same system could be implemented by having the systems open a socket connection to each other and send messages directly. In this way there is more code and less database access. This is the non-datacentric approach. Either of these could be implemented using OOP concepts.
Another example from my work we implement servers for games, one type of server handles multi-player game play so user presses the button and spaceship fires missile at other player. This server is not datacentric it is event based. Another server stores the users high scores, friend lists etc this server is thin wrapper over the database which stores the score and lists.
以数据为中心的设计是一种应用程序行为由数据封装的设计。一个简单的例子。考虑以下 OOP 类:
这是汽车的 OOP 表示。调用“move”方法将触发汽车开始移动。换句话说,任何副作用都是通过调用类方法来触发的。
这是相同的类,但以数据为中心:
为了让这辆车移动,我会“简单地”更改 x 和 y 的值。在大多数编程语言中,更改成员不允许执行逻辑,这就是为什么以数据为中心通常需要一个框架。
在这样的框架中,逻辑运行在 CRUD 的 C、U 和 D 之上。这样的框架将提供适当的设施来在任何这些事件中启用代码插入,例如:
以数据为中心的设计有很多含义。例如,由于应用程序状态由其数据有效表示,因此您可以自动保留应用程序。编写良好的以数据为中心的应用程序可以从数据库进行存储、停止和恢复,并像从未消失一样继续运行。
以数据为中心的设计非常适合传统的三层 Web 架构。 Web 应用程序通常由后端数据库的内容驱动。这就是为什么当您关闭并重新打开动态网页时,它看起来仍然相同(假设数据没有改变)。
A data centric design is one where the application behavior is encapsulated by data. A simple example. Consider the following OOP class:
This is an OOP representation of a car. Invoking the 'move' method will trigger the car to start moving. In other words, any side effects are triggered by invoking the class methods.
Here's the same class, but data centric:
In order to get this car moving, I would "simply" change the values of x and y. In most programming languages changing members won't allow for the execution of logic, which is why data centricity often requires a framework.
In such a framework, logic is ran upon the C, U and D of CRUD. Such a framework will provide the appropriate facilities to enable code insertion at any of these events, for example:
Data centric design has many implications. For example, since an application state is effectively represented by its data, you can automatically persist the application. A well-written data centric application can be stored, stopped and restored from a database, and continue like it was never gone.
Data centric designs are a good match for traditional 3 tier web architectures. Web applications are typically driven by the contents of the backend database. That is why, when you close and reopen a dynamic webpage, it still looks the same (provided the data didn't change).