Zillow 使用 Android 架构组件构建清晰的新代码
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。

Zillow 是一个顶级在线房地产市场,为消费者提供购买、出租或出售房屋所需的房源、数据和计算器。此外,该网站还将用户与本地代理人、抵押贷款提供商和家居设计师联系起来。
Zillow 成立于 2006 年,总部位于西雅图,维护着一个包含超过 1.1 亿美国家庭的数据库。他们还运营着一套(二十多个)热门的移动房地产应用。他们从 2017 年 7 月开始对 Android 移动应用中的代码进行重大改造,当时 Zillow 希望通过使代码更易于阅读且更容易让新团队成员理解来简化开发者的生活。
策略
Zillow 使用 Android 架构组件改进了他们的代码。
“我们正在研究使用不同类型的架构,”Zillow 软件工程师 Aayush Raj 说道,“架构组件还具有生命周期感知功能,可使代码更易于管理。”
ViewModel 允许数据在屏幕旋转等配置发生更改后继续存在,而 LiveData 是一种可观察的数据容器类。Zillow 同时使用这两个类来提供功能强大的模板,以实现 Model-View-ViewModel (MVVM)。“这样可以使我们的代码更易于测试。”Raj 说道。利用 Room 持久性库,开发者还可以轻松构建本地缓存层,因此应用不必经常从网络中提取数据,从而“改进性能和用户体验”。
结果
Raj 还讲道,将大量数据更新代码从 Activity 迁移到 ViewModels“绝对有助于”让整个代码库更易于阅读。
他们尚未将整个应用转换为 ViewModel,但使用 ViewModel 的组件未出现任何与生命周期相关的 bug。向 activity 和 fragment 传递数据更新的工作流也运行良好。
Zillow 高级软件开发工程师 Sumiran Pradhan 说:“通过使用 Android 架构组件,开发者的工作效率确实得到了提高”。
架构组件不仅可以在开发者从零开始开发应用时为他们提供指导,也可以在现有代码库中加以使用。“一旦新的开发者了解 ViewModel 中的逻辑所在,就会喜欢上它!”Pradhan 补充道。
开始使用
Android 架构组件作为 Android Jetpack 的一部分向所有开发者开放。开始使用 Android 架构组件。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2018-05-03。
[null,null,["最后更新时间 (UTC):2018-05-03。"],[],[],null,["# Zillow builds clear new code with Android Architecture Components\n\nZillow is a top online real estate marketplace that provides consumers with\nthe listings, data, and calculators they need to help them buy, rent, or sell\na home. The site also connects users with local agents, mortgage providers,\nand home designers.\n\nLaunched in 2006 and headquartered in Seattle, Zillow maintains a database\nof more than 110 million U.S. homes. They also operate a popular suite of\nover two dozen mobile real estate apps. When they began a major overhaul of\ntheir code in their Android mobile app in July 2017, Zillow wanted to simplify\ntheir developers' lives by making the code more readable and easier for\nnew team members to understand.\n\nWhat they did\n-------------\n\nZillow revamped their code using\n[Android Architecture Components](/topic/libraries/architecture).\n\"We were investigating different kinds of architecture,\" says Aayush Raj,\nZillow software engineer. \"Architecture Components had the added advantage of\nlifecycle awareness, which made code much easier to manage.\"\n\n[ViewModel](/topic/libraries/architecture/viewmodel) allows data to\nsurvive configuration changes (such as screen rotations), while\n[LiveData](/topic/libraries/architecture/livedata) is an observable\ndata-holder class. Both were used by Zillow, and together, they provided a\npowerful template for implementing Model-View-ViewModel (MVVM). \"It helped make\nour code more testable,\" Raj says. The\n[Room](/topic/libraries/architecture/room) persistency library also\nmade it easy to build a local cache layer, so the app didn't have to pull data\nfrom the network as often, \"improving performance and the user experience.\"\n\nResults\n-------\n\nMoving lots of code for data updates from activities to\n[ViewModels](/topic/libraries/architecture/viewmodel) has\n\"definitely helped\" make the whole code base more readable, Raj adds.\nThey haven't yet converted the whole app to\n[ViewModel](/topic/libraries/architecture/viewmodel),\nbut components that are using\n[ViewModel](/topic/libraries/architecture/viewmodel)\nhaven't had any lifecycle-related bugs. Communicating\ndata updates to activities and fragments also works very well.\n\n\"Developers are absolutely more productive using Android Architecture\nComponents,\" says Sumiran Pradhan, Zillow senior software development engineer.\nArchitecture Components gives them guidance when starting from scratch,\nbut is also useful in the existing code base. \"Once new developers\nunderstand where the logic lives in the\n[ViewModel](/topic/libraries/architecture/viewmodel), they love it,\"\nPradhan adds.\n\nGet started\n-----------\n\nAndroid Architecture Components is open to all developers as part of\n[Android Jetpack](/jetpack). Get\nstarted with [Android Architecture Components](/jetpack/arch)."]]