Clean Architecture in Android in 5 minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
only thing we know for sure in software development is that things are going to change and they're supposed to but clean architecture has just the right tool for it that's what they call the separation of concerns but before i start talking about separation of concerns please don't forget to like because that helps a lot now back to clean architecture this is what you're going to see when you search for a clean architecture in software development in general you can see that the the separation of concerns is implemented in four layers but in my experience in android and according to the projects that i've seen and that i work on usually those um the cleaner texture is implemented in three layers so the first layer is what they call the presentation layer some people also call it the ui layer and then we have the domain layer some people also call it the business layer and finally we have the data layer some people also call it repository layer for me name is not very important as long as there is a clear separation of those three layers in architecture so in the presentation layer is where you're going to put basically everything that you're using to display data to the user so activity fragment view views adapters view model literally everything that you're using to display colors and ui to the user and then we have the domain so let's use an e-commerce application as example for your domain one example of object in your domain layer would be a wish list for any comments and a use case would be adding a product to this wishlist and removing a product to this wish list you can see that there are some logics and some rules that you have to follow for those operations and those logic should be in in your domain and we also have data stores which are the definition or interfaces of how you're going to save retrieve and modify data as you can see those examples that i gave adding a product to the wish list removing a product to the wish list has nothing to do with android or ios or web it really belongs your business really belongs to your domain so in this domain in this layer you should avoid adding any any android apis so no fragment no views no context no resources nothing because if you do so you you would be breaking the idea of separation of concerns because all of that belongs to the presentation layer not the domain finally we have the data layer so the data layer is where you're going to fulfill all the promises that you've made in your domain so that's where you're going to implement your repositories and that's where you're going to have the implementation details of those repositories basically so if you have a repository that is fetching a products in your data layer you're going to have the implementation of that so basically you're going to communicate with either a database or shared preferences or an api so now that you know what are uh what are each of those layers and what goes in each of those layers as well now let's see how is the interaction between them so the presentation is allowed only to communicate with the domain it cannot communicate with the data layer and usually the way that you do it is by injecting the use cases and the interfaces of your repositories in your view model but remember those repositories they are interfaces they are not the implementation details because if you add the implementation details they belong to the data layer and that's breaking the idea of separation of concerns and the id is the same for the domain usually you have use cases and you can also inject other use cases inside your use cases and you can also have access to those interfaces for your repositories and your data stores finally in the in the data layer you were going to implement those data stores those repositories so if you're going to have a wishlist repository you can either use room or you can use shared preferences or an api to do it and this is how your uh your architecture is going to look like in my opinion i think that clean architecture has a lot of benefits it's very easy to understand it's very easy to maintain and it's also favor writing tests because you have a very clear separation of each layer it's very easy to write tests for it and in my opinion one of the main benefits is that making major changes like for example migrating from one api to another or even changing from a database to an api it's only going to affect your data layer for example so your domain your presentation will remain intact and that is a clean architecture in five minutes i hope that now you have a better understanding of clean architecture and you know how to build it and if you don't i have a three hours course about clinic tech tree in android the link for the course is in the description go check it out please don't forget to like and if i forgot to mention something mention in the comments that's it thanks for watching
Info
Channel: Renaro Santos
Views: 19,192
Rating: undefined out of 5
Keywords: android, clean architecture, mvvm, clean architecture android, android mvvm, kotlin, android kotlin, android architecture, android clean code
Id: K1aC7eO6vbw
Channel Id: undefined
Length: 5min 16sec (316 seconds)
Published: Fri Apr 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.