Coder Social home page Coder Social logo

architecture_practice's Introduction

Architecture_Practice

Android architecture patterns practice {MCV,MVP,MVVM} This Repository is initiated to practice 3 android architectures, explanation is provided by Ahmed Azz channel.

MVC:

  • Stands for Model-View-Controller.
  • Traditional architecture for mobile and web applications.
  • Define Model for data storage (data class, APIs, DB).
  • Depends on composition between the Controller and the View -> controller has reference of its view.
  • Android project affect this architecture to define both the controller and the view dependently (drawback).
  • Suits small applications.
Diagram

mvc

MVP:

  • Stands for Model-View-Presenter.
  • Try to separate computations from the View.
  • Computations are delegated to the Presenter.
  • Suits middle-size projects.
  • We need to define an interface for each View and then implement it.
    • This is the Preseneter responsibilities.
    • Presenter will get View's inputs using those functions declared in the interface.
    • Send data to model
    • Get updated data from model.
    • Send them back to the View (also we could do computations in presenter)
  • How the presenter will send data back to the view?
    • We need to define an interface for each view that will define functions with parameter of type model.
    • Those funcitons will be implemented in the View class -> get model object and update View's UI.
Diagram

mvp

MVVM

  • Most recent and most used architecture in large-size applications.
  • Based on Observer pattern.
  • Views are separated from the ViewModel.
  • ViewModel can't communicate directly with the Models.
  • Repositories will deal with Models (remote, local), update or fetch data to ViewModels.
  • Logic can be delegated to either ViewModel or the Repository.
    • For DIP and Strategy pattern: We declare repository interface then implement it, ViewModel will have a reference to repository interface to update or fetch data.

    • View must have a reference to ViewModel -> can be done through composition or XML tag.

    • ViewModel will get View's inputs then handle them to repository object defined in it.

    • Repository object will update model and fetch new updated data using MutableLiveData and return it to the VM.

    • VM will get repo's MutableLiveData, do computations and return final data to View as LiveData.

    • The View will observe ViewModel's data using:

      vmObj.observe(this,Observe{ liveDataObj->
        //update UI using liveDataObj's data
      })
      
Diagrams:

general mvvm

detailed mvvm

mvvm

Hope my explanation was easy to understand ๐Ÿ˜ŠโœŒ

architecture_practice's People

Contributors

mohammedysamir avatar

Watchers

 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.