Git Product home page Git Product logo

Comments (2)

fuzhengwei avatar fuzhengwei commented on May 27, 2024

作者你好,在看书中有个代码的实现细节不是很懂。
1.
在设计模式部分的itstack-demo-design项目中的itstack-demo-design/itstack-demo-design-2-02/src/main/java/org/itstack/demo/desgin/factory/JDKProxy.java 这个类里的方法
getProxy(Class《T》 interfaceClass, ICacheAdapter cacheAdapter)
中第一个参数是带泛型T,然后最后返回的值进行类型转换
return (T) Proxy.newProxyInstance(classLoader, new Class[]{classes[0]}, handler);
我想问的是在测试的时候
CacheService proxy_EGM = JDKProxy.getProxy(CacheServiceImpl.class, new EGMCacheAdapter());
这句话为什么第一个参数传入的是实现类的类对象,而不是接口的类型?
因为我看的一些动态代理介绍说的是对于产生的代理对象,不能强转为实现类,只能转为接口类型。
可能我对泛型理解的有问题 : (
2.第二个问题是对于设计模式这本书中,在其他资料上介绍说抽象工厂是工厂的工厂,我想问一下本书中的通过代理实现的抽象工厂,返回的这个代理对象是不是就是其他资料上指的,由抽象工厂产生的工厂?因为刚学设计模式,书里也没有明确点出,看的不是很懂。

  1. 而不是接口的类型,可以是接口类型,但是代码里需要修改下。代码里自己获取了接口类型
  2. 嗯,返回的就是工厂的工厂,用于使用不同的缓存服务

from itstack-demo-design.

meshow1 avatar meshow1 commented on May 27, 2024

了解,感谢回复:)

from itstack-demo-design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.