Thank you. I agree with the idea that the api should be friendly to user. Except constructor , "Simple Factory Pattern" makes this easy for API user to use, but the factory only creates one object. Your suggestion is provide one method for initialization , right? So, which way do you think is better, Factory or Constructor,?
Sheng Wu <[email protected]> 于2019年11月30日周六 下午9:57写道: > I think that is not a good principle, I suggest to design for API user > perspective. Will he/she use it separately? If yes, then WHY? > > If you could answer this, you have the answer already. > > guangyuan wang <[email protected]>于2019年11月30日 周六下午9:12写道: > > > Yes. > > The difference in my opinion, the constructor is only for creating an > > object and simple initialization(assignment operation) for attributes. > And > > Init method is for complex initialization for attributes. > > > > Sheng Wu <[email protected]> 于2019年11月30日周六 下午8:55写道: > > > > > Question, does constructor and #init are always being called together, > if > > > so, at least, you don’t need both of them. > > > The key of this discussion is, what is the difference logically in your > > > mind between constructor and #init method . > > > > > > guangyuan wang <[email protected]>于2019年11月30日 周六下午8:33写道: > > > > > > > And 4. "new ConfigTreeNode().init(param1,param2,param3);". > > > > > > > > Zonglei Dong <[email protected]> 于2019年11月30日周六 下午6:01写道: > > > > > > > > > Hi ShardingSphere community, > > > > > > > > > > > > > > > > > > > > Now, We are refactoring ShardingSphere’s orchestration module. We > > have > > > > > some problems and want to discuss with community. > > > > > > > > > > > > > > > For Apollo as a ConfigCenter, I want to construct a > “ConfigTreeNode” > > > > class > > > > > for representing the relationships between all config keys and it’s > > > > > childrenkeys, and the ConfigTreeNode class define a init() method > for > > > > > initialize > > > > > the relationships. > > > > > > > > > > > > > > > If we want to init the ConfigTree, we can call the init() method > like > > > > this: > > > > > > > > > > > > > > > ConfigTreeNode root = new ConfigTreeNode(param1, param2, param3); > > > > > root.init(param4, param5); > > > > > > > > > > > > > > > Some developer think this isn’t a good practice, want to combine > two > > > > lines > > > > > of code into one line. > > > > > > > > > > > > > > > We discuss some code styles: > > > > > > > > > > > > > > > 1. "ConfigTreeNodeFactory.init(param4, param5)”, but it must define > > > > > another ConfigTreeNodeFactory class; > > > > > > > > > > > > > > > 2. "new ConfigTreeNode(param1, param2, param3).init(param4, > param5)"; > > > > > > > > > > > > > > > 3. Auto call init() method in ConfigTreeNode’ constructor method, > and > > > > > caller doesn’t care of it. > > > > > > > > > > > > > > > Which does a good idea and do you have other good suggestions? > > > > > > > > > > > > > > > Thanks! > > > > > Zonglei Dong > > > > > Apache ShardingSphere > > > > > > > > > > > > > > > > > -- > > > Sheng Wu 吴晟 > > > > > > Apache SkyWalking > > > Apache Incubator > > > Apache ShardingSphere, ECharts, DolphinScheduler podlings > > > Zipkin > > > Twitter, wusheng1108 > > > > > > -- > Sheng Wu 吴晟 > > Apache SkyWalking > Apache Incubator > Apache ShardingSphere, ECharts, DolphinScheduler podlings > Zipkin > Twitter, wusheng1108 >
