使用延迟初始化。
延迟初始化:如果初始化成本过高,有时推迟初始化的过程是很有用的。
Lazy initialization: it sometimes makes sense to defer initialization if the cost of initialization is significant.
延迟初始化的主要弊端是,由于要查看属性是否已定义,如果没有,则得到它的值,这会使代码变得更复杂。
The main disadvantage of lazy initialization is your code becomes more complex because you need to check to see if the attribute has been defined yet and, if not, obtain its value.
应用推荐