java创建抽象方法_java – 创建新的抽象方法与接口方法

问:如果要在未链接到接口的抽象类中创建抽象方法,您是否仍遵循Program to the Interface的原则?

我已经为我创建的所有UI类使用了一个接口;但是,鉴于接口的原因,我没有看到与我想要创建的抽象方法和现有接口的直接关联.

通常,我只是创建抽象方法并完成;但是,我想知道我是否违反了程序到接口的设计原则.

问:我应该为此创建另一个接口还是坚持使用抽象方法?

注意:这不是接口与抽象类问题.

public abstract class BaseClass extends Clazz implements Interface {

// 1 out of 4 interface methods are implemented here

CustomObj getMode() { ... }

// I am actually also thinking of taking that 1 method - getMode() - out of the

// interface and implementing it as an implemented method without an interface.

// Method that made me ask this question!!

abstract CustomObj getDefaultMode(); // Not related to the interface - Interface

}

public interface Interface {

String getFirstNumber();

String getSecondNumber();

CustomObj getMode(); // This one is implemented in the BaseClass, but I think it no longer belongs in this role

// CustomObj getDefaultMode(); // This one is not in Interface, but makes be believe I need a new Interface or just have them declared in an Abstract Class.

}

注意:My Base类更多用于简化具体类中的代码.基类处理一些重写的​​方法,辅助方法,初始化等…所以它不像接口那样,而是作为标准的抽象类.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值