系统分析与设计作业5
1. 按用例构建领域模型
对于整个Hotel Reservation, 我把它分为以下三个子用例, 分别绘制领域模型图:
- 查找选择Hotel
- 生成Reservation过程
- 支付过程
注: 对于中介实体和识别实体,按照题目要求已在命名区分(E和M开头)
查找选择Hotel 领域模型
如下图:
这个领域模型是老师在上课的时候指导我们画的。
生成Reservation过程领域模型
这个模型中,所有设计的对象都用E,M 加以区分。在之后设计数据库时, 也是按照这里区分的对象来创建实体对象。
支付过程领域模型
2. 数据库建模(数据逻辑模型)
根据要求, 利用工具软件 PowerDesigner,绘制E-R模型 如下:
然后导出为Mysql 脚本,导出语句如下:
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2018/4/29 0:09:12 */
/*==============================================================*/
drop table if exists Hotel;
drop table if exists Location;
drop table if exists customer;
drop table if exists reservation;
drop table if exists room;
/*==============================================================*/
/* Table: Hotel */
/*==============================================================*/
create table Hotel
(
name text not null,
location text,
road text not null,
code decimal(6),
Loc_code decimal(6),
"star rating" float,
primary key (name)
);
/*==============================================================*/
/* Table: Location */
/*==============================================================*/
create table Location
(
code decimal(6) not null,
name text,
"hot index" numeric(8,0),
type text,
primary key (code)
);
/*==============================================================*/
/* Table: customer */
/*==============================================================*/
create table customer
(
fullname text,
"email address" text not null,
primary key ("email address")
);
/*==============================================================*/
/* Table: reservation */
/*==============================================================*/
create table reservation
(
name text,
customer text,
"check in date" datetime,
"check out date" datetime,
"room index" int not null,
price float,
"number of people" int,
hotel text not null,
"email address" text,
primary key ("room index", hotel)
);
/*==============================================================*/
/* Table: room */
/*==============================================================*/
create table room
(
"room index" int not null,
code decimal(6),
"hotel name" text not null,
name text,
type text,
isAvailable bool,
date datetime,
isSmokingAllowed bool,
primary key ("room index")
);
alter table Hotel add constraint "FK_located at" foreign key (Loc_code)
references Location (code) on delete restrict on update restrict;
alter table Hotel add constraint "FK_located in" foreign key (code)
references Location (code) on delete restrict on update restrict;
alter table reservation add constraint "FK_belonged to" foreign key (name)
references Hotel (name) on delete restrict on update restrict;
alter table reservation add constraint "FK_made by" foreign key ("email address")
references customer ("email address") on delete restrict on update restrict;
alter table room add constraint FK_Relationship_1 foreign key (code)
references Location (code) on delete restrict on update restrict;
alter table room add constraint FK_has foreign key (name)
references Hotel (name) on delete restrict on update restrict;
alter table room add constraint FK_included2 foreign key ("room index", "hotel name")
references reservation ("room index", hotel) on delete cascade on update cascade;
数据库逻辑模型 与 领域模型 的异同
我认为相同点主要在以下几个方面:
- 都是对实际问题的抽象,用于更直观的显示需求
- 两者都注重在对问题中的对象进行建模。 E-R模型中,问题对象为实体;领域模型中,问题对象转化为类。
- 两者在构建时有相似之处,领域模型需要分析所有的名词,从中提取出业务实体,区分名词中的属性,角色,实体,实例,形成操作实体集合;E-R模型的构建方法与此类似。不过稍有不同在于忽略中介实体。
我认为区别主要在以下两个方面:
- 领域模型侧重于显示不同对象之间的关系,而不是对象内的具体实现。领域模型需要标注对象之间的对应关系(one-one, one-many, many-one, many-many). E-R模型则需要八每个实体内部也进行详细的设计。这里体现两者抽象程度的区分
- E-R 模型中只涉及具体实际可视对象,即需要被记录的对象。而领域模型中显然既包括具体的实体集E, 也包含有中介实体M