数据库和UI之间的类

发布于 2024-11-25 06:42:17 字数 38 浏览 0 评论 0原文

我有一个类处理从数据库写入和读取数据。这个类的正确名称是什么?

I have a class that handles writing and reading data from my database. What is a proper name to call this class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软甜啾 2024-12-02 06:42:17

有几个约定。假设一个 Person 模型,您可以使用:

PersonDataAccessObject,
PersonDao,
PersonRepository,
PersonDataAccess,

...

它也取决于您正在使用的技术。我的意思是,谁知道您所使用的语言存在哪些约定。让我们知道什么语言和什么数据访问框架,答案可能会有所不同。

我过去常在后面加上“道”,因为它简短而清晰。但后来我更多地转向了 Martin Fowler 的词汇和模式,所以现在我使用存储库。啰嗦了一点,但我生性啰嗦,所以很适合我的风格。最后,这就是关键。这是风格上的,据我所知,没有全面的标准。最重要的是,你要选择明确的东西并持续使用它。如果您稍后决定切换到其他内容,请怜悯任何可能跟随您并重命名所有内容的程序员,以便所有数据访问组件的命名保持一致。

编辑:在重读本文时,我意识到我假设您将有多个这样的类,每个模型实体都有一个。谁知道你的设置是什么。如果您不打算这样做,而只是为所有数据访问的单个入口点寻找一个标准名称,则可以使用:

DataMapper
Gateway

通常,假设您将拥有多个这些围绕着您的每个“表”/模型实体。这不仅仅是命名约定,它可能是标准编码约定。这样,当您更改或添加与“persons”表交互方式的某些方面时,您不必修改包含访问“addresses”表的代码的类。查看 Martin Fowler 的企业应用程序架构模式 (PofEAA),了解更多

PofEAA 模式目录(查看数据源架构模式

<一个href="http://www.evansvillednug.com/LinkClick.aspx?fileticket=4LwCx2tkyBA=&tabid=76&mid=399" rel="nofollow">快速领域驱动设计(免费 pdf)第 3 章

There are a couple of conventions. Assuming a Person model, you could use:

PersonDataAccessObject,
PersonDao,
PersonRepository,
PersonDataAccess,

...

It is also dependent on the technology you are using. I mean, who knows what conventions exist for the language you are using. Let us know what language and what data access framework and the answer may vary.

I used to append "Dao" because it's short and clear. But then I moved over more to Martin Fowler's vocabulary and patterns, so now I use Repository. A little more long winded, but I'm long winded by nature, so it fits my style. In the end, that's the key. It's stylistic and there is no across the board standard that I'm aware of. What's most important is that you pick something that is clear and you use it consistently. If you decide, later on, to switch to something else, have mercy on any programmers that may follow you and rename everything so that all your data access components are consistently named.

Edit: in rereading this, I realized I am assuming you are going to have multiple such classes, one for each of your model entities. Who knows what your setup is. If you aren't going to do it like that, and you're just looking for a standard name for a single point of entry to all data access, you could use:

DataMapper
Gateway

Typically, the assumption is that you are going to have several of these around, one for each of your "tables"/model entities. More than a naming convention, that is probably a standard coding convention. This way, when you change or add some aspect of how you interact with your "persons" table, you don't have to modify a class in which you have code to access the "addresses" table. Check out Martin Fowler's Patterns of Enterprise Application Architecture (PofEAA), for more

PofEAA catalog of patterns (check out Data Source Architectural Patterns

and

Domain Driven Design Quickly (free pdf) esp. Ch. 3

邮友 2024-12-02 06:42:17

根据该类表示的实体,它可能是例如 Person。然后,您设计一个传递到 GUI 的 PersonViewModel。因此,您从数据库获取的 Person 被映射到 PersonViewModel,该模型被传递到 UI 层以某种形式显示。视图模型只是从数据库获取的域模型的表示,并且仅包含需要在给定 UI 上显示的必要信息。

Depending on the entity this class represents it could be for example Person. Then you design a PersonViewModel which is passed to the GUI. So the Person you got from the database is mapped to a PersonViewModel which is passed to the UI layer for being shown under some form. The view model is just a representation of the domain model you fetched from the database and containing only the necessary information that you need to display on the given UI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文