抽象的常见类如何?

时间:2015-10-10 08:48:25

标签: java abstract-class

使用JSF和Hibernate开发Web应用程序,具有Entity,Entity数据访问和& JSF以下列模式管理bean类,并在所有类中重复相同的重复。由于所有类都具有相同的模式,我想将其作为抽象类。

实体类

public class MyEntity {
-----
-----
}

数据访问类

public class MyEntityDAO extends AbstractDAO<MyEntity> {
MyEnitityDAO(){
-------
   }
}

JSF托管bean

public class MyBean implements Serializable {

private static final long serialVersionUID = 1L;
private MyEntity current;
private MyEntityDAO dao;
private DataModel<MyEntity> items = null;

public MyBean() {
    // TODO Auto-generated constructor stub
}

public MyEntity getCurrent() {
    return current;
}

public void setCurrent(MyEntity current) {
    this.current = current;
}

public MyEntityDAO getDao() {
    if (dao == null) {
        dao = new MyEntityDAO();
    }
    return dao;
}

public DataModel<MyEntity> getItems() {
    return items;
}

public List<MyEntity> getMyEntityList() {
    return getDao().findAll();
}
public MyEntity getMyEntity(int id) {
    return getDao().findById(id);
}
    private void reSetDataModel() {
    items = null;
}
private void reSetCurrent() {
    setCurrent(null);
}

public void prepareCreate() {
    current = new MyEntity();
}

public void create() {
    // Save the entity
}
public void edit() {
    // Update the entity
}
public void delete() {
    // Remove the entity
}
}

如何使抽象类脱离上述模式?

1 个答案:

答案 0 :(得分:0)

abstractpublic

之间输入单词class