当前位置:文档之家› 工厂方法模式设计的汽车保险管理应用程序实例

工厂方法模式设计的汽车保险管理应用程序实例

作业正文
作业一:
1、作业题目内容的详细描述。

【作业2.1-1】例2.3为使用工厂方法模式设计的汽车保险管理应用程序实例,现在需要扩张例2.3的设计图,添加一个名为LuxuryCarInsurance的类,并且需要编写此类和其他需要添加的类的代码,详细要求参见光盘的响应作业部分
2、完成本题目所采用的软件设计模式名称及画出相应的类图,或者是所采用的软件体系结构名称及画出相应的体系结构图。

该题目采用的是工厂方法模式,类图如下:
3、画出完成本题目所设计程序的设计类图;如还有其他图,也一并画出。

4、完成本题目所设计的程序代码。

(1)程序主界面的部分代码如下:
(添加汽车保险名)
FactoryMethodGUI
<<interface>> PolicvProducer getPolicyObj()
BodyInjurPolicyProducer
getPolicyObj() CollisionPolicyProducer
getPolicyObj() ComprihensivePolicyProducer
getPolicyObj() LuxeryyCarPolicyProducer
getPolicyObj()
PersonInjuryPolicyProducer
getPolicyObj() <<interface>> AutoInsurance getInsurDescription()
BodyInjurLiablility getInsurDescription()
LuxeryCarInsurance getInsurDescription()
PersonInjuryProtection getInsurDescription()
ComprehensiveCoverage getInsurDescription()
CollisionCoverage getInsurDescription()
(下拉框添加LuxeryCarInsurance保险选项)
(添加触发事件判断)
(2)创建LuxeryPolicy工厂类,实现PolicyProducer接口
(3)创建LuxeryCarInsurance类,实现AutoInsurance接口
5、程序运行的典型界面截图。

作业二:
1、作业题目内容的详细描述。

【作业2.1-2】在例2.4中,设计并且实现了豪华(Super)和中等(Medium)别墅(House)与公寓(Condo)的查询。

要求在该设计的基础上,增加一个新的类SemiDetacher(半独立式楼宇),并且编写代码,实现相应的查询功能,详细要求参见光盘的相应作业部分。

2、完成本题目所采用的软件设计模式名称及画出相应的类图,或者是所采用的软件体系结构名称及画出相应的体系结构图。

该题目采用的是抽象工厂模式,类图如下:
3、画出完成本题目所设计程序的设计类图;如还有其他图,也一并画出。

程序的设计类图如下:
4、完成本题目所设计的程序代码。

(1)程序主界面的部分代码如下:
界面的选择框以及按钮面板
B u i l d i n g F a c t o r y
g e t B u i l d i n g F a c t o r y(S t r i n g t y p e)
+g e t H o u s e:H o u s e
+g e t C o n d o:C o n d o
+g e t S e m i D e t a c h e r:S e m i D e t a c h e r
<<I n t e r f a c e>>
H o u s e
+g e t H o u s e I n f o
S u p e r H o u s e
+g e t H o u s e I n f o
M e d i u m H o u s e
+g e t H o u s e I n f o
I n t e r f a c e
C o n d o
+g e t C o n d o I n f o
S u p e r C o n d o
+g e t C o n d o I n f o
M e d i u m C o n d o
+g e t C o n d o I n f o
A b s t r a c t F a c t o r y G U I
M a i n
M e d i u m B u i l d i n g F a c t o r y
+g e t H o u s e:H o u s e
+g e t C o n d o:C o n d o
+g e t S e m i D e t a c h e r:S e m i D e t a c h e r
+
S u p e r B u i l d i n g F a c t o r y
+g e t H o u s e:H o u s e
+g e t C o n d o:C o n d o
+g e t S e m i D e t a c h e r:S e m i D e t a c h e r
I n t e r f a c e
S e m i D e t a c h e r
+g e t S e m i D e t a c h e r
I n f o
S u p e r S e m i D e t a c h e r
+g e t S e m i D e t a c h e r I n f o
M e d i u m S e m i D e t a c h e r
+g e t S e m i D e t a c h e r I n f o
create
create create
create
create
create
监听器代码,用于监听查询按钮(2)新增的SemiDetacher接口代码如下:
(3)新增的SuperSemiDetacher类代码如下:
(4)新增的MediumSemiDetacher类代码如下:
(5)BuidingFactory类代码如下:
(6)继承BuildingFactory的MediumBuildingFactory代码如下:
(6)继承BuildingFactory的SuperBuildingFactory代码如下:
5、程序运行的典型界面截图。

相关主题