r*******w 发帖数: 121 | 1 一个class,实现了很多的功能
现在想换一个implementation(原来的implementation同时也要用)
是不是应该提取一个interface出来
然后两个不同的implementation时parallel的关系呢?
还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢? |
s*******s 发帖数: 3 | 2 interface. it's not much of work
【在 r*******w 的大作中提到】 : 一个class,实现了很多的功能 : 现在想换一个implementation(原来的implementation同时也要用) : 是不是应该提取一个interface出来 : 然后两个不同的implementation时parallel的关系呢? : 还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢?
|
r*******w 发帖数: 121 | 3 how do you do static method in an interface/
还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢?
【在 s*******s 的大作中提到】 : interface. it's not much of work
|
r*******w 发帖数: 121 | 4 cannot do static method in an interface...
ft to death...
now have to modify many many things~~
?
【在 r*******w 的大作中提到】 : how do you do static method in an interface/ : : 还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢?
|
n*****k 发帖数: 123 | 5
May be you could use interface --> abstract class?
还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢
【在 r*******w 的大作中提到】 : cannot do static method in an interface... : ft to death... : now have to modify many many things~~ : : ?
|
F****n 发帖数: 3271 | 6 You still cannont inheritate static method in subclasses, so there is no
differences.
The only thing different is using interface you need to modify both your
original class and your new class, using inheritance you only need to take
care of the new one. But if you use interface, you can easily expand your code
in the future, say, if you want a third or fourth implementations.
还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢
【在 r*******w 的大作中提到】 : cannot do static method in an interface... : ft to death... : now have to modify many many things~~ : : ?
|
r*******w 发帖数: 121 | 7 this is a good suggestion!
indeed i have used abstract classes in other places...
but i have already changed everything to be based on interface...
and move all the static methods to a factory class...
maybe next time ba~~~
【在 n*****k 的大作中提到】 : : May be you could use interface --> abstract class? : 还是偷点懒儿,就让新的implementation继承前一个但是所有的function都overload呢
|