recently I listened to a lecture on spring source code, in which I didn"t quite understand the delegation mode. The delegation model that I understand is an intermediary. Class An encapsulates the method of class B, so that other classes just need to tune class An and do not need to know the existence of class B.
but in class, the delegation pattern I heard was different from what I understood.
the following is the source code in spring-version 5.0.2
ps:. I started with the refresh () method in the constructor in FileSystemXmlApplicationContext and looked down
example 1:AbstractApplicationContext class
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
//refreshBeanFactory()refreshBeanFactory()
refreshBeanFactory();
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
if (logger.isDebugEnabled()) {
logger.debug("Bean factory for " + getDisplayName() + ": " + beanFactory);
}
return beanFactory;
}
example 2:AbstractRefreshableApplicationContext class
@Override
protected final void refreshBeanFactory() throws BeansException {
//bean
if (hasBeanFactory()) {
destroyBeans();
closeBeanFactory();
}
try {
//IOC
DefaultListableBeanFactory beanFactory = createBeanFactory();
beanFactory.setSerializationId(getId());
//IOC
customizeBeanFactory(beanFactory);
//BeanloadBeanDefinitions
loadBeanDefinitions(beanFactory);
synchronized (this.beanFactoryMonitor) {
this.beanFactory = beanFactory;
}
}
catch (IOException ex) {
throw new ApplicationContextException("I/O error parsing bean definition source for " + getDisplayName(), ex);
}
}
there are many more. It is said that the delegated design pattern is used (and did not say why.. Otherwise, I wouldn"t be here to ask..). But I do not see that the delegate pattern is used, which is not inheriting the parent class and implementing the method defined by the parent class, so of course when the method is called, the method of the subclass is executed. The characteristics of the delegation model seem to have nothing to do with this.
Features of delegation mode:
1
2
3
google a lot, but there seems to be so little information about delegation mode in spring that nothing can be found. Very puzzled ah, there is no one who is proficient in spring source code, so I have no way to start, so I have no choice but to ask questions here, hoping that a great god can reply to me with a train of thought.