Coder Social home page Coder Social logo

thanghand / androidcleanarchitecture Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 244 KB

Android CleanArchitecture

JavaScript 1.89% TypeScript 29.72% Kotlin 1.87% Java 65.44% Groovy 1.08%
cleanarchitecture android clean-architecture clean-code backend android-cleanarchitecture

androidcleanarchitecture's Introduction

AndroidCleanArchitecture

  • Cooking (Android project)
  • Cooking-Backend (You have to start your backend first)
$ npm install yarn -g
$ yarn install
$ yarn build
$ yarn start

Problems when we use MVP, MVVM, MVC ...

What is Clean Architecture?

Architectural reactive approach

http://fernandocejas.com/2015/07/18/architecting-android-the-evolution/

  • Clean Architecture is a mindset of designed structure project. If you have read the "Clean code", you will know the rules to make your code clean.

    • Readable
    • Maintainable
    • Scalable
    • Extendable
    • Testable

Clean Architecture have the same rules with Clean Code.

  • When you apply "Clean Architecture" in your project, you will split your code to many files and make them to be independent. Class does not dependence with orther. It will do with its scope.

Do we need to split it to many files ?

  • Ok, I will give you some example here.

  • I have a project which apply MVP pattern. I have one Presenter to handle my bussiness case. If my presenter have 3 or 4 usecase, you will know that my code are really messy.

class HomePresenter {
  ... Many properties 
  ... Many variables to keep logic
  
  ... Logic A
  
  ...

}
  • My presenter will do a lot of things, and it contain many propterites and varaibles which they don't want to know. And they can make side effect.
  • If you maintain for this code, you really want to do it (@@).

The solutions for it, I will split bussiness logic to every files. When presenter want to use it just call them.

public class SearchRecipePresenter extends BasePresenter<SearchRecipeContract.ViewRecipeCallBack>
        implements SearchRecipeContract.Presenter {

    private final SearchRecipes searchRecipes;

    private final FilterRecipes filterRecipes;

    @Inject
    SearchRecipePresenter(SearchRecipes searchRecipes, FilterRecipes filterRecipes) {
        super(searchRecipes, filterRecipes);
        this.searchRecipes = searchRecipes;
        this.filterRecipes = filterRecipes;
    }

(This code in Cooking project)

  • The code is very clean right. If SearchRecipes change bussiness logic, I just go to SearchRecipes and change. And I really confident my changes does not affect to another logic.
  • Do you see @Inject anotation? We use dagger 2 to Inject the object. Dagger 2 is a library dependency injection (https://github.com/google/dagger)
  • If you apply Clean Architechture, you also should use Dagger 2. Because Dagger 2 is very helpful to inject object without knowing the parameter (A class shouldn’t know anything about how it is injected)

androidcleanarchitecture's People

Contributors

thanghand avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  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.