日期:2014-05-17  浏览次数:20586 次

问个问题,关于抽象类这么做有什么好处呢?新手求教

Java code

package po;
// Generated by MyEclipse - Hibernate Tools



/**
 * Toperator generated by MyEclipse - Hibernate Tools
 */
public class Toperator extends AbstractToperator implements java.io.Serializable {

    // Constructors

    /** default constructor */
    public Toperator() {
    }

    
    /** full constructor */
    public Toperator(String operatorName, String operatorPwd, Long isAdmin) {
        super(isAdmin, operatorName, operatorPwd, isAdmin);        
    }
   
}



------------------------
Java code

public abstract class AbstractToperator  implements java.io.Serializable {


    // Fields    

     private Long operatorId;
     private String operatorName;
     private String operatorPwd;
     private Long isAdmin;


    // Constructors

    /** default constructor */
    public AbstractToperator() {
    }

    /** minimal constructor */
    public AbstractToperator(Long operatorId) {
        this.operatorId = operatorId;
    }
    
    /** full constructor */
    public AbstractToperator(Long operatorId, String operatorName, String operatorPwd, Long isAdmin) {
        this.operatorId = operatorId;
        this.operatorName = operatorName;
        this.operatorPwd = operatorPwd;
        this.isAdmin = isAdmin;
    }

   
    // Property accessors

    public Long getOperatorId() {
        return this.operatorId;
    }
    
    public void setOperatorId(Long operatorId) {
        this.operatorId = operatorId;
    }

    public String getOperatorName() {
        return this.operatorName;
    }
    
    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

    public String getOperatorPwd() {
        return this.operatorPwd;
    }
    
    public void setOperatorPwd(String operatorPwd) {
        this.operatorPwd = operatorPwd;
    }

    public Long getIsAdmin() {
        return this.isAdmin;
    }
    
    public void setIsAdmin(Long isAdmin) {
        this.isAdmin = isAdmin;
    }
   






------解决方案--------------------
抽象类用的不太多的,主要也是就减少点代码量,体现在一个抽象类有多个子类的时候;个人感觉接口好用,建议楼主了解下面向接口编程的思想,之后你自己就明白优缺点了!
------解决方案--------------------
设计思想问题
我觉得工作一段时间就会体会到其中的好处了