English 中文(简体)
施工后现场
原标题:Init field after constructor execution

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>将卡路从验证方法转向每一种私人方法,还有第三种办法。

我应选择哪一种三种方法?

最佳回答

我认为,第2条办法是一种反pat,应当加以避免,它类似于臭名昭著的<条码>。 简单表格类别(如无国籍状态和安全隐形,但不是这样)。

Regarding the other approaches, if you really have many private methods it would be better to use the 1st approach, otherwise you can use the 3rd approach, it doesn t look too ugly for me.

还指出,使用第1条办法“如同”涉及的,与第3条相比,更多的是政变。 在第3起案件中,你可以通过事先配置的鉴定人,使验证人的客户脱离其实施,而在第1起案件中,你需要引进一个工厂,以实现同样的效果。

问题回答

www.un.org/spanish/ecosoc 良好做法通常可以避免倒退。

使用第二种方法。 如果您重新制定<代码>CarValidator等值,并打电话validate(car),对您的物体进行核查,这似乎非常有效。 我不理解,为什么你会认为这不是一种最佳做法?

你们是否关心建立一个私人的<代码>Car变量,并在整个验证过程中加以提及,而不是通过所有私人方法进行检验? 只要<代码>validate方法同步进行,这种做法就是一个问题。

我将采用第四种办法,并尽早通过将拆解剂标物列入“Carructors。 我认为,较之于在多个地方(即不快) having倒和必须检查有效性的无效车辆(通过有效性()或由Validator物体的属性)的回击率要小得多。


最新情况:如果你在施工期间无法证实Carlys的事例,例如,由于你在客户方面重复了,我将把Carly作为你的服务器方面的固定价值,并使用和你的方法2来加以控制。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签