Singleton, the builder pattern

Purpose and task

Objective: familiar with the UML, familiar with the singleton, builder mode.

Tasks: in accordance with the requirements of the experiment content, done using the singleton, builder model to achieve experimental content.

Content preview

Review the contents of UML course, familiar with the Singleton pattern, using the builder pattern.

Experiment contents and requirements

  • Example single mode:

Please read in conjunction with singleton pattern achieved (refer to JSP course code) based txt profile.

Txt file you can create your own, for example:

1   2003    Spring  Soccer League (Spring '03)

2   2003    Summer  Summer Soccer Fest 2003

3   2003    Autumn  Autumn Soccer League (2003)

4   2004    Spring  Soccer League (Spring '04)

5   2005    Summer  The Summer of Soccer Love 2005

6   2006    Autumn  Autumn Soccer League (2006)

Please put the file in a directory, and reads information using a single embodiment of the file mode (note that the file format and content, self-defined), placed in memory for the system to call other modules.

  • Use the builder pattern:

You can use the existing computer products according to customer demand without CPU, RAM, motherboard form games on your computer and office computer, try builder described the scene mode, it requires the drawing class diagrams and Coding.

The results (available Continued)

One:

 

Read the results:

 

two:

Abstract builder (Bulid):

ComputerBulider.java:

Specific builder (ConcreteBulid):

GameComputerBulider.java:

officeComputerBulider.java:

 

Director ( director):

Director.java:

Product ( Product):

Computer.java:

CPU.java:

MotherBoard.java:

 

RAM.java:

Main:

Main.java:

运行结果:

类图:

思考题:

  1. 请给出在java语言种用单例模式的应用?

懒汉式,饿汉式,双重检索式,注册登记式,内部类形式

2、单例模式分为饿汉式和懒汉式,如何区别?

饿:上来就创建好实例对象,直接返回
懒:用的时候再在方法里创建,但懒汉式存在线程安全问题

3、请给出实验内容2中的时序图,请问如果增加一种中档电脑,系统如何变化?给出类图。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/yszbrzdd/article/details/93520922