slievrly commented on code in PR #6420: URL: https://github.com/apache/incubator-seata/pull/6420#discussion_r1527553505
########## config/seata-config-core/src/main/java/org/apache/seata/config/CachedConfigurationChangeListener.java: ########## @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.config; + +public interface CachedConfigurationChangeListener extends ConfigurationChangeListener { + + ConfigurationCache CONFIGURATION_CACHE = ConfigurationCache.getInstance(); + + @Override + default void afterEvent(ConfigurationChangeEvent event) { + ConfigurationChangeListener listener = (ConfigurationChangeListener)CONFIGURATION_CACHE; + listener.onProcessEvent(event); Review Comment: > > > > CachedConfigurationChangeListener is an instance that holds state. > > > > > > > > > Since we must notify ConfigurationCache, and ConfigurationCache also implements ConfigurationChangeListener, why do we need to use it to make it strong, instead of defining it in a member variable? 既然必定要通知到ConfigurationCache,而且ConfigurationCache 也是实现了ConfigurationChangeListener,为什么要在使用使强壮,而不再成员变量中定义好? > > > > > > Sorry, I'm unable to understand the logic expressed here. > > Why not define it as a ConfigurationChangeListener afterListener = ConfigurationCache.getInstance(); when the member variable is defined, instead of doing the type conversion in afterEvent? 为什么不在成员变量定义的时候就定义为一个ConfigurationChangeListener afterListener = ConfigurationCache.getInstance(); 而是在afterEvent中再进行类型转换? I understand what you mean. However, this might be related to my personal habits. It can be replaced with one line syntactically, but in reality, it involves two steps. But from a design perspective, I would like to point out a few things. Member variables are intended for internal use within a class to maintain consistency in the architecture. Once converted into an interface here, it means that other methods can only use methods defined by the interface. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
