4

请教一个 Java 设计模式的问题

 1 year ago
source link: https://www.v2ex.com/t/887449
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

请教一个 Java 设计模式的问题

  dumbbell5kg · 2 小时 19 分钟前 · 430 次点击
  • 之前看 spring 代码的时候发现了这样的写法:
GenericApplicationContext implements BeanFactory{
    BeanFactoryImp beanFactoryImp;
    
    @Override
	public Object getBean(String name) throws BeansException {
		return getBeanFactoryImp().getBean(name);
	}
}
  • 我觉得这样写的好处是通过 GenericApplicationContext 来使用 BeanFactory 提供的 getBean()等方法时,不需要写成这样 new GenericApplicationContext().getBeanFactory().getBean(name),而直接是 new GenericApplicationContext().getBean(name)。

  • 我现在也有个场景想要使用这种技巧,但是我不知道接口名字,也就是上面代码的 BeanFactory 该怎么命名,所以这种技巧是一个什么模式吗,我想用这种模式的名字来命名我的接口类,比如 BeanFactoryFacade ?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK