Git Product home page Git Product logo

architecture_showcase's Introduction

Showcase repository for android application architecture

This is a project that accompanies a lecture on software architecture. The 2022 recording is available on YouTube. The description of this app starts with this slide. This is a simple application that contains a list of articles. You can bookmark or delete each article. The list of articles and their authors are loaded asynchronously and combined using the author id.

!!!WARNING!!!

  • The project is structured by architecture layers, i.e. there are folders data, domain and ui. This is done for demonstration purposes, and this is not how we usually structure applications. Usually classes are divided into modules by feature, for example, all classes associated with an article will be located in the article folder, and, as a rule, there will be fewer folders, and the project structure will be flatter.
  • This lecture precedes a lecture on Dependency Injection, so all the code related to DI is written manually. In real projects, DI frameworks should be used to avoid boilerplate code. The most popular choice for large projects is Dagger 2.

Data flow

Data is loaded from the HardCodedDataSource. It uses delays to simulate asynchhronous loading. Repositories (ArticleRepository and AuthorRepository) are responsible for retreiving the data from data source and caching it into LiveDatas. (ArticlesWithAuthorsUseCase is observing LiveDatas from the repositories and merges them into one LiveData<ArticlesWithAuthor> using MediatorLiveData. (ArticlesViewModel is observing this MediatorLiveData. It maps ArticlesWithAuthor into ArticleItemModel using Transformations.map to prepare the data for displaying. Classes that are displaying data observe the LiveData of the ViewModel. There is an ArticlesFragment that delegates most of its work to ArticlesViewController to move code out of the system-managed classes. ArticlesViewController observes changes of the ViewModel and pushes new data int ArticlesListAdapter.

User events and data loading requests are propagated upwards using the usual and suspend method calls. Whenever data changes, all classes get their updated version via LiveData subscriptions, and the user interface is updated automatically. A single source of truth ensures that all data is consistent and up-to-date.

Lifecycles

On the slide each next lifecycle is nested inside the previous one. Accessing classes with one lifecycle from the classes with another lifeycle should be done with care to avoid memory leaks. On the slide, each next lifecycle is nested in the previous one.

Components

Components are responsible for creating classes, obtaining the required dependencies, and storing references to the created classes. Usually each component is tied to one lifecycle, but there can be multiple components in each lifecycle.

architecture_showcase's People

Contributors

yndx-evgeek avatar ktolnos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.