1、 领域建模
- a. 阅读 Asg_RH 文档,按用例构建领域模型。
- 按 Task2 要求,请使用工具 UMLet,截图格式务必是 png 并控制尺寸
- 说明:请不要受 PCMEF 层次结构影响。你需要识别实体(E)和 中介实体(M,也称状态实体)
- 在单页面应用(如 vue)中,E 一般与数据库构建有关, M 一般与 store 模式 有关
- 在 java web 应用中,E 一般与数据库构建有关, M 一般与 session 有关
【答】 按照用例图中提取出的实体名词,除了购物车是中介实体(M)外,其他都是实体(E),因为购物车不需要储存在数据库中,而像预订的房间等都需要储存在数据库中。虽然Task2中说到creditCard不是中介实体而是实体,但是数据库实际只要保存是否支付成功就可以了,要验证信用卡安全可以在前端进行,储存信用卡信息没太大用处。
- b. 数据库建模(E-R 模型)
- 按 Task 3 要求,给出系统的 E-R 模型(数据逻辑模型)
- 建模工具 PowerDesigner(简称PD) 或开源工具 OpenSystemArchitect
- 导出 Mysql 物理数据库的脚本
- 简单叙说 数据库逻辑模型 与 领域模型 的异同
【答】
使用PD画出数据逻辑模型:查询结果里,多间不同的旅馆坐落在目的地中,目的地由地名标识,每个旅馆由旅馆ID标识,一个旅馆内有许多房间,房间由房号标识,每一个预订都是预订房间,而每一个预订可能预订多个房间;每个旅客进行预订,但是可能不只有一个预订,每份预订由reservationID标识。billAmount指每份预订的花费,detail指每份预订的备注。
通过PD还可以由数据逻辑模型自动生成物理模型,导出的Mysql物理数据库的脚本如下
drop table if exists Customer;
drop table if exists Hotel;
drop table if exists Location;
drop table if exists Reservation;
drop table if exists Room;
drop table if exists payment;
/*==============================================================*/
/* Table: Customer */
/*==============================================================*/
create table Customer
(
customerID numeric(8,0) not null,
name varchar(40) not null,
"email address" varchar(40) not null,
primary key (customerID)
);
/*==============================================================*/
/* Table: Hotel */
/*==============================================================*/
create table Hotel
(
hotelID numeric(8,0) not null,
code numeric(8,0),
hotelName varchar(40) not null,
hot float not null,
star float not null,
description varchar(200),
primary key (hotelID)
);
/*==============================================================*/
/* Table: Location */
/*==============================================================*/
create table Location
(
code numeric(8,0) not null,
region varchar(40) not null,
city varchar(40) not null,
town varchar(40) not null,
hot float,
primary key (code)
);
/*==============================================================*/
/* Table: Reservation */
/*==============================================================*/
create table Reservation
(
reservationID numeric(8,0) not null,
customerID numeric(8,0),
paymentID numeric(8,0),
"total due" float(8,2) not null,
"special requirements" varchar(200),
isSmoking bool,
isConfirmed bool not null,
primary key (reservationID)
);
/*==============================================================*/
/* Table: Room */
/*==============================================================*/
create table Room
(
roomNumber numeric(8,0) not null,
hotelID numeric(8,0),
reservationID numeric(8,0),
roomType varchar(40) not null,
date date not null,
isAvaliable bool not null,
"list price" float(8,2) not null,
"number of adults" numeric(8,0) not null,
"number of children" numeric(8,0),
primary key (roomNumber)
);
/*==============================================================*/
/* Table: payment */
/*==============================================================*/
create table payment
(
paymentID numeric(8,0) not null,
isSucceed bool not null,
primary key (paymentID)
);
alter table Hotel add constraint "FK_locate in" foreign key (code)
references Location (code) on delete restrict on update restrict;
alter table Reservation add constraint FK_make foreign key (customerID)
references Customer (customerID) on delete restrict on update restrict;
alter table Reservation add constraint "FK_pays for" foreign key (paymentID)
references payment (paymentID) on delete restrict on update restrict;
alter table Room add constraint FK_has1 foreign key (hotelID)
references Hotel (hotelID) on delete restrict on update restrict;
alter table Room add constraint "FK_reserved by" foreign key (reservationID)
references Reservation (reservationID) on delete restrict on update restrict;
数据库逻辑模型与领域模型的异同:
领域模型就是在了解了用户的需求,用户的业务领域工作情况以后,经过分析和总结,提炼出来的用以描述用户业务需求的一些概念的东西,描述的是业务中涉及到的业务实体以及相互之间的关系, 它可以帮助需求分析人员和用户(或用户代表)认识实际业务。
逻辑模型是领域模型的延伸,就是要将概念模型具体化,表示概念之间的逻辑次序,是一个属于方法层次的模型。具体来说,逻辑模型中一方面显示了实体、实体的属性和实体之间的关系,另一方面又将继承、实体关系中的引用等在实体的属性中进行展示。
总的来说,领域模型和逻辑模型都是用于描述用户业务需求的模型,表达了实体之间的关系;
但是逻辑模型是系统设计,以及实现的一部分,描述的是对用户需求在技术上的实现方法;而领域模型只是业务描述中提炼出来的一些概念以及其关系,与软件开发没有关系。