什么是延迟初始化,为什么是它有用吗? [英] What is lazy initialization and why is it useful?

查看:696
本文介绍了什么是延迟初始化,为什么是它有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是对象的初始化工作?你是怎么做到这一点,有什么优势?

What is lazy initialization of objects? How do you do that and what are the advantages?

推荐答案

延迟初始化是你延迟(潜在的昂贵)对象的创建,直到刚刚在你真正需要它的性能优化。

Lazy Initialization is a performance optimization where you defer (potentially expensive) object creation until just before you actually need it.

一个很好的例子是不创建数据库连接了前面,但仅仅只之前,你需要从数据库中获取数据。

One good example is to not create a database connection up front, but only just before you need to get data from the database.

键这样做的原因是,(通常),您可以完全避免创建对象,如果你永远不需要它。

The key reason for doing this is that (often) you can avoid creating the object completely if you never need it.

这篇关于什么是延迟初始化,为什么是它有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆