泛型对象的应用:常规业务逻辑模板化,使用通用的父类来定义字段,具体字段由实现类来赋予数据

2024-10-09 10:49:01 浏览数 (3)

泛型对象的应用:常规业务逻辑模板化,使用通用的父类来定义字段,具体字段由实现类来赋予数据

代码语言:javascript复制
//DEMO-1
public interface CommonTemplateService<T,F> {
    public T buildCallbackParam(String orderNo);

    public F doCallback(String callbackUrl, String requestBody);
}

//实现类继承
public class UserService extends AbstractCommonService implements CommonTemplateService<PartnerBaseRequest, PartnerBaseResponse> {




//DEMO-2
public interface CommonTemplateService {
    public PartnerBaseRequest buildCallbackParam(String orderNo);

    public PartnerBaseResponse doCallback(String callbackUrl, String requestBody);
}

//实现类继承
public class UserService extends AbstractCommonService implements CommonTemplateService {



//支付宝源码代码参考:
public interface AlipayRequest<T extends AlipayResponse>{

public abstract class AlipayResponse implements Serializable {

public <T extends AlipayResponse> T execute(AlipayRequest<T> request) throws Exception {

}

//实现类
public class AlipayAcquirePayRequest extends BaseVo implements AlipayRequest<AlipayAcquirePayResponse>{

0 人点赞