You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by guangyuan wang <wa...@apache.org> on 2019/12/01 06:25:18 UTC

Re: [ShardingOrchestration][Discuss] The best practice for define a Class and it's init() method

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 <wu...@gmail.com> 于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 <wa...@apache.org>于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 <wu...@apache.org> 于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 <wa...@apache.org>于2019年11月30日 周六下午8:33写道:
> > >
> > > > And  4. "new ConfigTreeNode().init(param1,param2,param3);".
> > > >
> > > > Zonglei Dong <dz...@163.com> 于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
>