UML 类图与 ER 数据库图

发布于 2024-09-04 00:31:16 字数 405 浏览 4 评论 0原文

我有点困惑,我正在开发一个程序,该程序由两部分组成,服务器和客户端,有组,位置,消息......存储在服务器中,客户端必须与其连接。我设计了用例图、活动图,还设计了类图。

问题是我想在 mysql 表中实现服务器来存储用户、组、地点...组中的用户...所以我设计了一个由 6 个表组成的 ER 图,但问题是我认为我的类图和 ER 图看起来太相似,我的意思是,我认为我做得不对,因为实际上每个表都有一个类,当我必须提取系统上的所有用户时,我是否这样做必须首先将所有行转换为对象,然后为每个修改的对象写入数据库?

对我来说,简单的选择是将整个应用程序仅基于数据库,并创建一个类来提取和插入数据,但我必须遵循 UML 规范,并且我有点困惑如何处理该类图,因为我读过的书说我必须为程序的每个“实体”创建一个类。

抱歉我的英语不好。

谢谢。

I'm a little confused, I'm developing a program, the program consist in two parts, the server and the clients, there are groups, places, messages... stored in the server, and the clients has to connect with it. I've design the use cases diagram, the activity diagrams, and I have design the class diagram too.

The thing is that I want to implement the server in a mysql tables for storing the users, groups, places... users in groups... so I've designed a E-R diagram consisting in 6 tables, but the problem is that I think that my class diagram and my ER diagram looks too similar, I mean, I think I'm not doing things right because I have a class for each table practically, and when I have to extract all the users on my system, do I have to convert all the rows into objects at first and write in the database for each object modified?

The easy choice for me would be to base my whole application only in the database, and making a class to extract and insert data in it, but I have to follow the UML specification and I'm a little confused what to do with the class diagram, because the books I have read say that I have to create a class for each "entity" of my program.

Sorry for my bad English.

Thank you.

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

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

发布评论

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

评论(1

世界和平 2024-09-11 00:31:17

我之前已经解决过这个问题几次,我是这样解决的:

1.)Select(继承自Vector,它存储具有标准类的所有行,具体取决于您正在使用的语言)结构:

ID(和 ID 可用于识别您的选择)
(Select 的所有元素(Vector 类的子级)都是行)

rowNumber: int

columnNumber:

intusedFilter: StringusedGroupBy

: StringusedHavingCaluse

: StringusedOrderBy

: String

tableName: String

getID()

getRowNumber(): int

getColumnNumber( ): int

getUsedFilter(): String

getUsedGroupBy(): String

getUsedHavingClause(): String

getUsedOrderBy(): String

getTableName(): String

Select(tableName: String, filter:String, groupBy: String,havingCaluse: String, orderBy: String, columns: Vector)

2.) 我有一个用于与数据库直接通信的类,我们将其称为 DataAccessLayer。我们来看看这个类的结构:

DataAccessLayer

connect(...): boolean

disconnect(...): boolean

use(databaseName: String): boolean

selectedData: Vector (实际上这是一组Select的)

createSelect(tableName: String,filter:String,groupBy:String,havingCaluse:String,orderBy:String,columns:Vector):boolean(判断是否成功)

deleteSelect(ID):boolean

insert(tableName:String,columns:Vector,values:Vector ):布尔

更新(表名:字符串,columnsToSet:向量,值:向量,过滤器:
String): boolean

delete(tableName: String, filter: String): int (删除了多少行, -1 if
发生异常,或者只是简单地将异常抛出到更高的级别)

//创建/删除表/视图/数据库/约束也可以实现,我只是//懒惰这样做,因为我确信你已经明白了 的想法

DataAccessLayer()

前两个步骤发生后,您可以使用两个类处理任何数据库查询(实际上 Select 的功能也可以放入 DataAccessLayer 中,使两个类成为一个类,但这样更优雅),但是,您可能想为几张表处理一些额外的事情。解决方案很简单,每当您发现一个表难以使用这些时,您只需继承 DataAccessLayer 并重新定义您想要重新定义的内容,因此在 DataAccessLayer 中您应该只使用 protected 和 public 修饰符,而忘记 private 修饰符。因此,关系将是:

Select 1 <-> n DataAccessLayer

ClassInheritedFromDataAccessLayer 扩展 DataAccessLayer

前端使用 ClassInheritedFromDataAccessLayer1, ..., ClassInheritedFromDataAccessLayern, DataAccessLayer。

这样你的项目将是:
- 易于管理
- 已订购
- 易于计划
- 易于实施
- 易于修改
- 易于其他人理解

我希望这有帮助,

问候。

I've solved this problem a few times before and I have solved it in this way:

1.) Select (inherited from Vector, it's storing all the rows with standard classes, depending on the language you are working in) Structure:

ID (and ID useful to identify your select)
(all the elements of the Select, which is a child of your Vector class are rows)

rowNumber: int

columnNumber: int

usedFilter: String

usedGroupBy: String

usedHavingCaluse: String

usedOrderBy: String

tableName: String

getID()

getRowNumber(): int

getColumnNumber(): int

getUsedFilter(): String

getUsedGroupBy(): String

getUsedHavingClause(): String

getUsedOrderBy(): String

getTableName(): String

Select(tableName: String, filter:String, groupBy: String, havingCaluse: String, orderBy: String, columns: Vector)

2.) I had a class for direct communication with the database, let's call it DataAccessLayer. Let's see the structure of this class:

DataAccessLayer

connect(...): boolean

disconnect(...): boolean

use(databaseName: String): boolean

selectedData: Vector (in fact this is a set of Select's)

createSelect(tableName: String, filter: String, groupBy: String, havingCaluse: String, orderBy: String, columns: Vector): boolean (to determine if it's successful)

deleteSelect(ID): boolean

insert(tableName: String, columns: Vector, values: Vector): boolean

update(tableName: String, columnsToSet: Vector, values: Vector, filter:
String): boolean

delete(tableName: String, filter: String): int (how many rows were deleted, -1 if
Exception occured, or just simply throw the Exception to a higher level)

//creating/dropping tables/views/databases/constraints can be implemented too, I'm just //lazy to do that, because I'm sure you already understand the idea

DataAccessLayer()

After the first two steps occured, you can handle any database query with two classes (in fact the functionality of Select can be put into DataAccessLayer too, making one class of the two, but it's more elegant this way), but, you might want to handle some extra things for a few tables. The solution is simple, whenever you find a table difficult to use with these, you just have to inherit from DataAccessLayer and redefine what you want to redefine, so in DataAccessLayer you should only use protected and public modifiers and forget the private modifier. So, the relations will be:

Select 1 <-> n DataAccessLayer

ClassInheritedFromDataAccessLayer extends DataAccessLayer

Frontend uses ClassInheritedFromDataAccessLayer1, ..., ClassInheritedFromDataAccessLayern, DataAccessLayer.

This way your project will be:
- managable
- ordered
- easy to plan
- easy to implement
- easy to modify
- easily understood by other people

I hope this helps,

Regards.

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