Suppose a Car Validator and many methods that read its attributes to valid them. Thus, the best way to structure it is to make Car an instance field.
实现这一目的有两个途径:
1>使构造者作为论据,然后打电话确认。
<>2> 拆除所有建筑商,而是通过行车验证方法作为论据:验证(汽车)。
如果我们想到,这一验证者必须不断验证,就请说500辆汽车。
With the 1) method, 500 validator objects must be instanciated ... Even if Garbage collector is doing its job really well, it doesn t seem to be the best practice. The benefit is that initialization of Car field is made by constructor => so more natural way.
有了2>方法,我们避免了1>的疏漏,但我们必须将Car Field推到验证方法中,这意味着在建造物体之后。 是否认为这是良好做法? 事实上,只有验证使用卡路里的方法,而且,只有验证方法不是私人的。
当然,为了避免所有怀疑=1>将卡路从验证方法转向每一种私人方法,还有第三种办法。
我应选择哪一种三种方法?