软件设计模式与体系结构 下载本文

.

(5)else if(selection.equals(ELLIPSOID) )

(6)else if(type.equals(ELLIPSOID)){

GridBagLayout gridbag = new GridBagLayout(); typePanel.setLayout(gridbag);

GridBagConstraints gbc = new GridBagConstraints();

txtEllipsoidRadius_a = new JTextField(8); txtEllipsoidRadius_b = new JTextField(8); txtEllipsoidRadius_c = new JTextField(8);

JLabel lblRadius_a = new JLabel(\ JLabel lblRadius_b = new JLabel(\ JLabel lblRadius_c = new JLabel(\

displayNewGUI( getTypePanel(ELLIPSOID));

form = new Ellipsoid(a, b, c);

}

String b_radius = txtEllipsoidRadius_b.getText(); String c_radius = txtEllipsoidRadius_c.getText();

double a = Double.valueOf(a_radius);

double b =Double.valueOf(b_radius);

double c = Double.valueOf(c_radius);

-

.

typePanel.add(txtEllipsoidRadius_a); typePanel.add(txtEllipsoidRadius_b); typePanel.add(txtEllipsoidRadius_c); typePanel.add(lblMeasure);

typePanel.add(lblRadius_a); typePanel.add(lblRadius_b); typePanel.add(lblRadius_c);

typePanel.add(cmbMeasure);

gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 0; gbc.gridy = 0;

gbc.insets.top = 5; gbc.insets.bottom = 5; gbc.insets.left = 1; gbc.insets.right = 8;

gridbag.setConstraints(lblRadius_a, gbc); gbc.gridx = 1;

gbc.gridy = 0;

gridbag.setConstraints(txtEllipsoidRadius_a, gbc); gbc.gridx = 0;

gbc.gridy = 1;

-

.

gridbag.setConstraints(lblRadius_b, gbc); gbc.gridx = 1;

gbc.gridy = 1;

gridbag.setConstraints(txtEllipsoidRadius_b, gbc); gbc.gridx = 0;

gbc.gridy = 2;

gridbag.setConstraints(lblRadius_c, gbc); gbc.gridx = 1; gbc.gridy = 2;

gridbag.setConstraints(txtEllipsoidRadius_c, gbc); gbc.gridx = 0;

gbc.gridy = 3;

gridbag.setConstraints(lblMeasure, gbc); gbc.gridx = 1;

gbc.gridy = 3;

gridbag.setConstraints(cmbMeasure, gbc);

}

【实验结果】

-

.

【实验小结】

通过这次实验我们大概理解了桥接模式,通过关联“抽象层次类”与“具

体层次类”这一桥梁,将表示两个维度的层类(数据结构)粘贴在一起,形成更大的数据结构,而这种变化又不会对现有的类产生影响,这种思路的终极想法是将软件设计的抽象部分与实现部分分离,使它们都可以独立的变化。

访问者模式——计算机部件销售软件

【实验内容】

在例4.5的设计中添加一个类SoundBox。该类实现接口ComputerParts,并且其他的计算机部件的类的结构类似。

【添加代码】

1、添加SoundBox类:

public class SoundBox implements ComputerParts{ public static final String NAME = \

private final double PRICE = 127.00;

-