Eclipse RCP应用系统开发方法与实战
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人

2.6.4 基本对象设计

按照面向对象的分析与设计方法的基本思想,“万物皆对象”,把“对象”作为解决问题的重心。根据测算系统的具体分析情况,系统主要对象有用户、教学单位、课程、公共参数、经费等。

1.用户对象Users

用户对象代表登录用户。从前面的图2-1用例图可以看到,系统用户划分成三类:学校领导和财务处为一类,除了拥有财务处的全部权限以外,还具有“确定分配基数”权限;教务处为第二类用户,除了拥有教学单位的全部权限以外,还具有“调整模型参数权限”;教学单位为第三类用户,具有测算经费、查看作为测算结果的Excel报表权限。说明:本书为了简化处理,在具体实现测算系统时将学校领导、财务处和教务处设置为相同权限。该对象代码如下。

        package cn.edu.jfcs.model;
        public class Users {
            private int id;              //记录ID
            private String username;      //用户名
            private String password;      //密码
            private String usertag;      //用户类别
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
            public String getPassword() {return password;}
            public void setPassword(String password) {this.password = password;}
            public String getUsername() {return username;}
            public void setUsername(String username) {this.username = username;}
            public String getUsertag() {return usertag;}
            public void setUsertag(String usertag) {this.usertag = usertag;}
        }

2.课程对象Course

Course是指用户在本地操作所涉及的课程对象,该对象比较简单,代码如下。

        package cn.edu.jfcs.model;
        import java.math.BigDecimal;
        public class Course {
            private int id;              //记录ID
            private String term;         //学期
            private int nian;            //年份
            private String unitid;        //教学单位代码
            private String courseid;      //课程代码
            private String coursetype;    //课程类别
            private String coursename;    //课程名称
            private String classname;     //班级名称
            private int nj;              //学生数
            private int n2j;             //学时数
            private BigDecimal r1j;      //学生层次系数
            private BigDecimal r2j;       //课程或专业系数
            private BigDecimal r3j;       //课程质量系数
            private TeachUnit teachunit;  //所属的教学单位
            public String getClassname() {return classname;}
            public void setClassname(String classname){this.classname=classname;}
            public String getCourseid() {return courseid;}
            public void setCourseid(String courseid) {this.courseid = courseid;}
            public String getCoursename() {return coursename;}
            public void setCoursename(String coursename){this.coursename=coursename;}
            public String getCoursetype() {return coursetype;}
            public void setCoursetype(String coursetype){this.coursetype=coursetype;}
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
            public int getN2j() {return n2j;}
            public void setN2j(int n2j) {this.n2j = n2j;}
            public int getNian() {return nian;}
            public void setNian(int nian) {this.nian = nian;}
            public int getNj() {return nj;}
            public void setNj(int nj) {this.nj = nj;}
            public BigDecimal getR1j() {return r1j;}
            public void setR1j(BigDecimal r1j) {this.r1j = r1j;}
            public BigDecimal getR2j() {return r2j;}
            public void setR2j(BigDecimal r2j) {this.r2j = r2j;}
            public BigDecimal getR3j() {return r3j;}
            public void setR3j(BigDecimal r3j) {this.r3j = r3j;}
            public TeachUnit getTeachunit() {return teachunit; }
            public void setTeachunit(TeachUnit teachunit){this.teachunit=teachunit;}
            public String getTerm() {return term;}
            public void setTerm(String term) {this.term = term;}
            public String getUnitid() {return unitid;}
            public void setUnitid(String unitid) {this.unitid = unitid;}
        }

这里有一个很奇怪的地方,各种系数是否要用BigDecimal类型?更恰当的类型似乎应该是float类型。这实际上涉及到精确度问题。如果采用float类型,输入的数值1.2在屏幕上可能会变成1.18。如果计算10.0~9.0,结果可能是0.999,而不是1.0!使用BigDecimal则可以执行精确小数运算,从而解决该问题。另外,代码中的teachunit属性表示该课程所属的教学单位对象,该对象后面将有说明。

3.经费对象Calcresult

本来并不需要经费对象,因为全部经费数据都可以通过计算得到。但是考虑到各教学单位查询较为频繁,为了避免每次查询均需要计算一次,因此特别设计了经费对象。实际上,用于保存测算结果的数据量比较小,牺牲这点儿空间换取较高的性能还是值得的。该对象类代码如下。

        package cn.edu.jfcs.model;
        public class Calcresult {
            private int id;                  //记录ID
            private int nian;                //年份
            private String unitid;            //教学单位ID
            private float ui;                //学生经费
            private float pi;                //专业培养费
            private float ci;                //公共课经费
            private float ryjf;               //人员经费
            private float zhywf;              //综合业务费
            private TeachUnit teachunit;      //所属教学单位
            public float getCi() {return ci;}
            public void setCi(float ci) {this.ci = ci;}
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
            public int getNian() {return nian;}
            public void setNian(int nian) {this.nian = nian;}
            public String getUnitid() {return unitid;}
            public void setUnitid(String unitid) {this.unitid = unitid;}
            public float getPi() {return pi;}
            public void setPi(float pi) {this.pi = pi;}
            public float getRyjf() {  return ryjf;}
            public void setRyjf(float ryjf) {this.ryjf = ryjf;}
            public float getUi() {return ui;}
            public void setUi(float ui) {this.ui = ui;}
            public TeachUnit getTeachunit() { return teachunit;}
            public void setTeachunit(TeachUnit teachunit) {this.teachunit = teachunit;}
            public float getZhywf() {return zhywf;}
            public void setZhywf(float zhywf) {this.zhywf = zhywf;}
        }

4.教学数据库服务器上的课程信息对象CourseInfo

CourseInfo对应远程教学数据库服务器上的课程对象,本书所使用的教学数据库服务器为MySQL 5.0。该对象类代码如下。

        package cn.edu.jfcs.model;
        public class CourseInfo {
            private int id;              //记录ID
            private String term;          //学期
            private int nian;            //年份
            private String unitid;        //教学单位代码
            private String courseid;      //课程代码
            private String coursename;    //课程名称
            private String coursetype;    //课程类别
            private String classname;     //班级名称
            private int nj;              //学生数
            private int n2j;             //学时数
            public String getClassname() {return classname;}
            public void setClassname(String classname){this.classname=classname;}
            public String getCourseid() {return courseid;}
            public void setCourseid(String courseid) {this.courseid = courseid;}
            public String getCoursename() {return coursename;}
            public void setCoursename(String coursename){this.coursename=coursename;}
            public String getCoursetype() {return coursetype;}
            public void setCoursetype(String coursetype){this.coursetype=coursetype;}
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
            public int getN2j() {return n2j;}
            public void setN2j(int n2j) {this.n2j = n2j;}
            public int getNian() {return nian;}
            public void setNian(int nian) {this.nian = nian;}
            public int getNj() {return nj;}
            public void setNj(int nj) {this.nj = nj;}
            public String getTerm() {return term;}
            public void setTerm(String term) {this.term = term;}
            public String getUnitid() {return unitid;}
            public void setUnitid(String unitid) {this.unitid = unitid;}
        }

5.公共参数对象PubData

公共参数对象与全校全局测算参数有关,代码如下。

        package cn.edu.jfcs.model;
        import java.math.BigDecimal;
        public class PubData {
            private int id;                  //记录ID
            private int nian;                //年份
            private BigDecimal mt;            //年度拟拨付总额
            private BigDecimal rte;           //全校本年应收金额
            private BigDecimal mte;           //全校本年实收金额
            private BigDecimal sjf;            //全校缴费率标准
            private BigDecimal uper;          //学生经费分割比
            private BigDecimal pper;          //专业培养费分割比
            private BigDecimal cper;          //公共课经费分割比
            private BigDecimal jcjper;        //奖酬金比率
            private BigDecimal xsknbzper;     //学生困难补助比率
            private BigDecimal xshdjfper;     //学生活动经费比率
            private BigDecimal xsjxjper;      //学生奖学金比率
            private BigDecimal tb1;           //教授A系数
            private BigDecimal tb2;           //教授B系数
            private BigDecimal tb3;           //教授C系数
            private BigDecimal tb4;           //教授D系数
            private BigDecimal tb5;           //副教授A系数
            private BigDecimal tb6;           //副教授B系数
            private BigDecimal tb7;           //讲师
            private BigDecimal tb8;           //助教
            public BigDecimal getCper() {return cper;}
            public void setCper(BigDecimal cper) { this.cper = cper;}
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
            public BigDecimal getJcjper() {return jcjper;}
            public void setJcjper(BigDecimal jcjper) {this.jcjper = jcjper;}
            public BigDecimal getMt() {return mt;}
            public void setMt(BigDecimal mt) {this.mt = mt;}
            public BigDecimal getMte() {return mte;}
            public void setMte(BigDecimal mte) {this.mte = mte;}
            public int getNian() {return nian;}
            public void setNian(int nian) {this.nian = nian;}
            public BigDecimal getPper() {return pper;}
            public void setPper(BigDecimal pper) { this.pper = pper;}
            public BigDecimal getRte() {return rte;}
            public void setRte(BigDecimal rte) {this.rte = rte;}
            public BigDecimal getSjf() {return sjf;}
            public void setSjf(BigDecimal sjf) {this.sjf = sjf;}
            public BigDecimal getTb1() {return tb1;}
            public void setTb1(BigDecimal tb1) {this.tb1 = tb1;}
            public BigDecimal getTb2() {return tb2;}
            public void setTb2(BigDecimal tb2) {this.tb2 = tb2;}
            public BigDecimal getTb3() {return tb3;}
            public void setTb3(BigDecimal tb3) {this.tb3 = tb3;}
            public BigDecimal getTb4() {return tb4;}
            public void setTb4(BigDecimal tb4) {this.tb4 = tb4;}
            public BigDecimal getTb5() {return tb5;}
            public void setTb5(BigDecimal tb5) {this.tb5 = tb5;}
            public BigDecimal getTb6() {return tb6;}
            public void setTb6(BigDecimal tb6) {this.tb6 = tb6;}
            public BigDecimal getTb7() {return tb7;}
            public void setTb7(BigDecimal tb7) {this.tb7 = tb7;}
            public BigDecimal getTb8() {return tb8;}
            public void setTb8(BigDecimal tb8) {this.tb8 = tb8;}
            public BigDecimal getUper() {return uper;}
            public void setUper(BigDecimal uper){this.uper = uper;}
            public BigDecimal getXshdjfper() {return xshdjfper;}
            public void setXshdjfper(BigDecimal xshdjfper){this.xshdjfper=xshdjfper;}
            public BigDecimal getXsjxjper() {return xsjxjper;}
            public void setXsjxjper(BigDecimal xsjxjper) {this.xsjxjper = xsjxjper;}
            public BigDecimal getXsknbzper() {return xsknbzper;}
            public void setXsknbzper(BigDecimal xsknbzper){this.xsknbzper=xsknbzper;}
        }

6.教学单位年度基本数据对象YearTeachUnit

该对象用来描述教学单位本身的基本状态信息。不同年份各教学单位的基本数据可能不同。例如,某个教学单位在不同年份的状态信息,是否有专业课、公共课是否可能发生变化,比如经济管理学院2006年只有专业课,但2007年可能开设企业管理全校公共课。其次,众所周知的事情,某个教学单位在不同年份的经费相关信息经常发生变化。例如,不同职称的教师人数、师生比、教学业务费、师资培养费等。代码如下。

        package cn.edu.jfcs.model;
        import java.math.BigDecimal;
        public class YearTeachUnit {
            private int id;                  //记录ID
            private int nian;                //年份
            private String unitid;            //教学单位ID
            private String haszyk;            //是否有专业课
            private String hasggk;             //是否有公共课
            private int ssb;                 //师生比
            private BigDecimal jfys;          //学费应收金额
            private BigDecimal jfss;          //学费实收金额
            private BigDecimal jxywper;        //教学业务费比例
            private BigDecimal jxglper;       //教学管理费比例
            private BigDecimal jxyjper;       //教学研究费比例
            private BigDecimal szpyper;       //师资培养费比例
            private int ta1;                 //教授A等人数
            private int ta2;                 //教授B等人数
            private int ta3;                 //教授C等人数
            private int ta4;                 //教授D等人数
            private int ta5;                 //副教授A等人数
            private int ta6;                 //副教授B等人数
            private int ta7;                 //讲师人数
            private int ta8;                 //助教人数
            private TeachUnit teachunit;      //所属教学单位
            public String getHasggk() {return hasggk;}
            public void setHasggk(String hasggk) {this.hasggk = hasggk;}
            public String getHaszyk() {return haszyk;}
            public void setHaszyk(String haszyk) {this.haszyk = haszyk;}
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
            public BigDecimal getJfss() {return jfss;}
            public void setJfss(BigDecimal jfss) {this.jfss = jfss;}
            public BigDecimal getJfys() {return jfys;}
            public void setJfys(BigDecimal jfys) {this.jfys = jfys;}
            public BigDecimal getJxglper() {return jxglper;}
            public void setJxglper(BigDecimal jxglper) {this.jxglper = jxglper;}
            public BigDecimal getJxyjper() {return jxyjper;}
            public void setJxyjper(BigDecimal jxyjper) {this.jxyjper = jxyjper;}
            public BigDecimal getJxywper() {return jxywper;}
            public void setJxywper(BigDecimal jxywper) {this.jxywper = jxywper;}
            public int getNian() {return nian;}
            public void setNian(int nian) {this.nian = nian;}
            public int getSsb() {return ssb;}
            public void setSsb(int ssb) {this.ssb = ssb;}
            public BigDecimal getSzpyper() {return szpyper;}
            public void setSzpyper(BigDecimal szpyper) {this.szpyper = szpyper;}
            public int getTa1() {return ta1;}
            public void setTa1(int ta1) {this.ta1 = ta1;}
            public int getTa2() {return ta2;}
            public void setTa2(int ta2) {this.ta2 = ta2;}
            public int getTa3() {return ta3;}
            public void setTa3(int ta3) {this.ta3 = ta3;}
            public int getTa4() {return ta4;}
            public void setTa4(int ta4) {this.ta4 = ta4;}
            public int getTa5() {return ta5;}
            public void setTa5(int ta5) {this.ta5 = ta5;}
            public int getTa6() {return ta6;}
            public void setTa6(int ta6) {this.ta6 = ta6;}
            public int getTa7() {return ta7;}
            public void setTa7(int ta7) {this.ta7 = ta7;}
            public int getTa8() {return ta8;}
            public void setTa8(int ta8) {this.ta8 = ta8;}
            public TeachUnit getTeachunit() {return teachunit;}
            public void setTeachunit(TeachUnit teachunit){this.teachunit=teachunit;}
            public String getUnitid() {return unitid;}
            public void setUnitid(String unitid) {this.unitid = unitid;}
        }

7.教学单位对象

无论哪个学校,都有教学单位的基本信息,如教学单位代码、教学单位名称。对于共性部分,可以统一在接口之下,并用一个抽象类统一实现接口中的公共属性。具体介绍如下。

(1)接口类ITeachUnit的代码如下所示。

        package cn.edu.jfcs.model;
        public interface ITeachUnit {
            public String getUnitid();
            public void setUnitid(String unitid);
            public String getUnitname();
            public void setUnitname(String unitname);
        }

(2)抽象类AbstractTeachUnit的代码如下所示。

        package cn.edu.jfcs.model;
        public abstract class AbstractTeachUnit implements ITeachUnit {
            private String unitid;            //教学单位ID
            private String unitname;          //教学单位名称
            public String getUnitid() {return unitid;}
            public String getUnitname() {return unitname;}
            public void setUnitid(String unitid) {this.unitid = unitid;}
            public void setUnitname(String unitname) {this.unitname = unitname;}
        }

(3)教学单位对象类TeachUnit的代码如下所示。

        package cn.edu.jfcs.model;
        public class TeachUnit extends AbstractTeachUnit {
        private int id;                      //记录ID
            public int getId() {return id;}
            public void setId(int id) {this.id = id;}
        }

8.用户登录对象SaveLogInfo

SaveLogInfo通常用于临时保存登录信息,该对象实际上完全可以不需要,是一个“冗余”对象。这里创建该对象的目的纯粹是为了处理方便,其代码如下。

        package cn.edu.jfcs.model;
        public class SaveLogInfo {
            private String username;          //用户名
            private String password;          //密码
            private String usertag;           //用户类别
            private static SaveLogInfo INSTANCE=new SaveLogInfo();
            private SaveLogInfo() {}
            public static SaveLogInfo getInstance() {return INSTANCE;}
            public String getPassword() {return password;}
            public void setPassword(String password) {this.password = password;}
            public String getUsername() {return username;}
            public void setUsername(String username) {this.username = username;}
            public String getUsertag() {return usertag;}
            public void setUsertag(String usertag) {   this.usertag = usertag;}
        }