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 持續性程式庫也可讓您輕鬆建構本機快取層,因此應用程式不必像「改善效能和使用者體驗」經常從網路提取資料即可。
成果
將大量資料更新的程式碼從活動移至 ViewModels 已「確實有幫助」,讓整個程式碼集更容易理解,Raj 也新增了更多程式碼。他們尚未將整個應用程式轉換為 ViewModel,但使用 ViewModel 的元件不會發生任何生命週期相關錯誤。對活動和片段進行通訊資料更新也有不錯的效果。
Zillow 資深軟體開發工程師 Sumiran Pradhan 表示「開發人員使用 Android 架構元件後能力大幅提升。架構元件在從頭開始設計時會提供指引,但對於現有程式碼集也很實用。Pradhan 補充道:「新開發人員瞭解邏輯在 ViewModel 中的位置後,就會愛上它。」
開始使用
Android 架構元件開放所有開發人員使用,這是 Android Jetpack 的一部分。開始使用 Android 架構元件。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2018-05-03 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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)."]]