Mission impossible? (babysloth, wangwenyou, jimjxr, abcabcabc please come in)
Now we have Array interface, Sequence interface, 4 decorator classes RotateSequence, ReverseSequence, SliceSequence, ConcatSequence, 1 bridge class Array2Sequence
(people who don't know the background of this question, please refer
http://www.csdn.net/expert/topic/690/690270.xml?temp=.7524835 and
http://www.csdn.net/expert/topic/700/700322.xml?temp=.7635614)
we use state pattern, responsibility chain, bridge pattern, decorator pattern in those classes.
And that pretty much solves our nested decorator problem.
Wonderful world, isn't it?
In my practice, I also have read-only array, write-only array, typed array etc.
public interface ArrayR
{
public int getLength();
public Object get(int i);
}
public interface ArrayW
{
public int getLength();
public void set(int i, Object val);
}
public interface Array extends ArrayR, ArrayW
{
public int getLength();
public Object get(int i);
public void set(int i, Object val);
}
public interface TypedArray extends Array
{
public Class getComponentType();
}
So that, in a method like ArrayUtil.binarySearch(ArrayR, Object, Comparator), I can search any ArrayR. (it does not have to be writable).
In a method like ArrayUtil.copyArray(ArrayR, ArrayW), the source array only needs to be readable, the dest array only needs to be writable.
OK. since we have slice, rotate, reverse, concat operations on Array, there's no reason we don't have them for ArrayR, ArrayW, TypedArray.
If I implement RotateSequenceR, ReverseSequenceR, RotateSequenceW etc, the impl will be pretty much the same as what we do for Array and Sequence. I can do copy&paste+minor changes, and I'll be all set.
That means, I'll need to write (or copy) similar code for 3*5=15 times. And if I also introduce TypedArrayR, TypedArrayW, the number will become 25.
Hooray! We are done!
But, wait a minute! Is that so great though? COPY&PASTE! Bad smell, isn't it?
How can I avoid copy&paste and reuse code as much as possible?
I don't have a solution in Java. Could not figure out a neat way even with GJ's parametric polymorphism. But C++'s template approach might work for this case. (not sure though)
Guys, your expertise is called for!
Babysloth: your ideas?
(people who don't know the background of this question, please refer
http://www.csdn.net/expert/topic/690/690270.xml?temp=.7524835 and
http://www.csdn.net/expert/topic/700/700322.xml?temp=.7635614)
we use state pattern, responsibility chain, bridge pattern, decorator pattern in those classes.
And that pretty much solves our nested decorator problem.
Wonderful world, isn't it?
In my practice, I also have read-only array, write-only array, typed array etc.
public interface ArrayR
{
public int getLength();
public Object get(int i);
}
public interface ArrayW
{
public int getLength();
public void set(int i, Object val);
}
public interface Array extends ArrayR, ArrayW
{
public int getLength();
public Object get(int i);
public void set(int i, Object val);
}
public interface TypedArray extends Array
{
public Class getComponentType();
}
So that, in a method like ArrayUtil.binarySearch(ArrayR, Object, Comparator), I can search any ArrayR. (it does not have to be writable).
In a method like ArrayUtil.copyArray(ArrayR, ArrayW), the source array only needs to be readable, the dest array only needs to be writable.
OK. since we have slice, rotate, reverse, concat operations on Array, there's no reason we don't have them for ArrayR, ArrayW, TypedArray.
If I implement RotateSequenceR, ReverseSequenceR, RotateSequenceW etc, the impl will be pretty much the same as what we do for Array and Sequence. I can do copy&paste+minor changes, and I'll be all set.
That means, I'll need to write (or copy) similar code for 3*5=15 times. And if I also introduce TypedArrayR, TypedArrayW, the number will become 25.
Hooray! We are done!
But, wait a minute! Is that so great though? COPY&PASTE! Bad smell, isn't it?
How can I avoid copy&paste and reuse code as much as possible?
I don't have a solution in Java. Could not figure out a neat way even with GJ's parametric polymorphism. But C++'s template approach might work for this case. (not sure though)
Guys, your expertise is called for!
Babysloth: your ideas?
...全文
相关推荐
C51单片机课程设计密码锁
微机原理及单片机应用技术课程设计,C51的密码锁。內部包含完整的仿真以及源代码 详细解释可以看我对应的博客
波形发生器幅频响应校准:项目应用中的关键步骤
深入探讨波形发生器在实际项目应用中的幅频响应校准方法,确保信号输出精度。通过系统化操作提升波形发生器稳定性与可靠性,满足高要求测试环境。
TI AWR2243 4D毫米波雷达校准实战:从角反射器到192通道校准矩阵生成全流程
本文详细介绍了TI AWR2243 4D毫米波雷达的校准实战流程,从角反射器设置到192通道校准矩阵生成的全过程。通过硬件配置、数据采集、距离维FFT处理及校准矩阵生成等关键步骤,确保雷达系统的高精度性能。特别适用于自动驾驶感知系统的开发与优化。
FFT增益揭秘:从数学定义到幅值校准的实践指南
本文深入解析FFT增益问题,从数学定义出发揭示幅值校准的关键技术。通过MATLAB和Python实例演示,详细讲解三种实用的幅值校准方法,包括幅度谱校准、功率谱校准和分段处理技巧,帮助工程师准确处理多频信号与泄露效应,避免常见实践误区。
基于c51单片机的课程设计
逻辑图、 源程序 、 硬件原理图、参考文献、设计原理、心得体会都有,完整篇!


Java SE
