我有以下我想要通用的学习课程:
public abstract class Study<
T1 extends Context,
T2 extends Region,
T3 extends Domain<T2>,
T4 extends Solution> {...
派生类的示例如下:
public class AmericanCultureStudy<
T1 extends AmericanCultureContext,
T2 extends AmericanCultureRegion,
T3 extends AmericanCultureDomain<T2>,
T4 extends AmericanCultureSolution>
extends Study<T1, T2, T3, T4> {...
public class ContemporaryAmericanCultureStudy<
T1 extends ContemporaryAmericanCultureContext,
T2 extends ContemporaryAmericanCultureRegion,
T3 extends ContemporaryAmericanCultureDomain<T2>,
T4 extends ContemporaryAmericanCultureSolution>
extends AmericanCultureStudy<T1, T2, T3, T4> {...
public class ContemporaryMainstreamAmericanCultureStudy<
T1 extends ContemporaryMainstreamAmericanCultureContext,
T2 extends ContemporaryMainstreamAmericanCultureRegion,
T3 extends ContemporaryMainstreamAmericanCultureDomain<T2>,
T4 extends ContemporaryMainstreamAmericanCultureSolution>
extends ContemporaryAmericanCultureSolution<T1, T2, T3, T4> {...
这种设计的结果是主代码中类的实例化变得繁重,如下所示:
ContemporaryMainstreamAmericanCultureStudy<
ContemporaryMainstreamAmericanCultureContext,
ContemporaryMainstreamAmericanCultureRegion,
ContemporaryMainstreamAmericanCultureDomain<
ContemporaryMainstreamAmericanCultureRegion>,
ContemporaryMainstreamAmericanCultureSolution>
study = new ContemporaryMainstreamAmericanCultureStudy<
ContemporaryMainstreamAmericanCultureContext,
ContemporaryMainstreamAmericanCultureRegion,
ContemporaryMainstreamAmericanCultureDomain<
ContemporaryMainstreamAmericanCultureRegion>,
ContemporaryMainstreamAmericanCultureSolution>() ;
尽管不同,但包含的所有类Study
都是相同的关注类型,因此必须有一种方法通过减少Study
.
任何人都可以帮助解决这个问题吗?谢谢