The domain layer does not care how the number trivia will be gotten it just cares that it will be gotten right this is all possible with an interface or because dart does not support interfaces we have to use abstract classes and then the other side of the coin or in this case repository is inside the data layer the data layer will define how the data will be gotten and managed and all of that we're get to that in just a short while but the important thing is that the repository in the data layer will implement the abstract class so it will have to conform to the so-called contract so that domain can really not care what's going on behind the scenes it just knows what kind of data it will always receive from the repository in this case it will be the number trivia so let's create the folder structure shall we inside VS Code the domain layer will have three subfolders entities which will be the number trivia entity which will simply hold the text of the trivia and the number of the number trivia then we will have also another subfolder repositories this is where the contract or the abstract class of repository will go and then also the last folder is use cases so use cases are get concrete number trivia and as you can see there was some server failure now so error handling works correctly but I don't know why there was a server failure but anyway now we have 42 so this is the concrete or get concrete use case and we also have the random use case and let's now move on to the data layer as you already know it contains repositories which implement the abstract classes from the domain so that they will have to just fulfill the contract defined by domain and then it also contains remote data sources local data sources any kind of data sources obviously go into the data layer usually you have one data source for getting remote data from the API and then you also have another one for getting local data in our case we will use shared preferences to cache the data locally and local data sources are also where you would have your for example GPS location code and all of that good stuff data sources do not have to just operate with databases they can also operate with the underlying platform or device and the repository is the brains of the data layer because this repository will decide when to cache, what to cache, when to get data from the remote data source, when to get data from local data source so for example if there is no internet connection we definitely want to get data the cached data from local data sources and you may notice that repositories output entities which kind of makes sense and again entity is just the number and the text of the number trivia really simple in our case but data sources do not output entities they deal with something called models and this nomenclature is really not all that important it doesn't matter how you call these things it's just that you know what those names mean and the reason behind having models is that transforming raw data which is for example JSON requires some conversion logic because we cannot work with JSON in our app we have to Dart objects but now let's think about this we definitely do not want to put our JSON conversion logic so to JSON and from JSON as we are all used to for example from built value or JSON serializable we do not want to put those conversion methods into entities and why is that well entities should be completely platform and data layer independent so for example if we switch from JSON to XML or to some binary data craziness we do not want to change the domain layer at all we only want to change the data layer when something data related changes but the domain should remain untouched therefore these models will be simple classes which extend entities and add some functionality on top of them and because they are subclasses of entities we can then simply cast them into entities and the repository will output the entity which does not have any additional functionality or fields added on top of it in the number trivia app since we do not have anything really difficult to do models will have only to JSON and from JSON methods but if you are storing something locally in an sqli database and for some reason you have to have the id inside the database stored inside the model you can also add some custom fields to the model not just methods in our app the remote data source will perform an HTTP get request to numbers API which is simply numbersapi.com and all of these links and all of that which I am explaining here is also available from the written tutorial so definitely check that out but here is numbersapi.com this is the API we will be using so as you can see we can get random trivia right this is what we are doing from within the app so this is what the remote data source will do it will perform get requests and then we have also local data source which will simply cache data using the shared preferences package and then these two data sources will be just a simple thing it will check whether or not the user is connected to the internet if there is internet connection it will always prefer to get fresh data from the remote data source if there is no internet it will get the cached data and it will also have a simple caching logic which is that we always cache everything as soon as it's gotten from the API so that if there is no internet connection it will always return the cached data the last cached data to be precise all right so let's now create the folder structure even for the data layer because the things below are not actually a part of our app these are some external things we do not care about them it's not a part of our code base and the data layer will be comprised of data sources, models and finally implementations of repositories so the repositories folder in data will hold implementations and the repositories folder in domain will hold the abstract classes or interfaces which are the contracts which the repositories implemented in data must fulfill and again this abstraction is necessary so that the domain layer can be completely independent of every other layer all right so this first part of this test driven development clean architecture flutter course was really theory heavy that's because something like clean architecture requires a lot of explanation because after all you cannot just start building a house without first planning how the house will look like you have to have at least some basic structure some basic drawings in place and these drawings were laid down in this first part so in the next parts we are going to actually get coding and doing test driven development and we are going to start off with this domain layer so if you do not want to miss that tutorial and more other tutorials like this definitely subscribe to this channel and also join the notification squad by hitting the bell button to make sure you grow your flutter skills because here on resocoder i am determined to provide you with the best app development tutorials and resources out there also make sure to check out the written tutorial available from the link in the video description to go through all of this at your own pace you will highly benefit from reading the written tutorial if you want to learn the most about clean architecture which i'm sure you want to do if this video helped you with clearing the concepts of clean architecture give it a like and also share it with our developers who will surely benefit from this too follow me on instagram i go under the name resocoder everywhere leave a comment if you have anything to say any suggestions or questions stay tuned for the next part in which we are going to finally start writing code doing test-driven development and see you in the next video you領域層並不關心數字瑣事將如何被獲取,它只關心數字瑣事是否被正確獲取,這一切都可以通過接口來實現,或者因為 dart 不支持接口,我們必須使用抽象類,然後硬幣的另一面,或者在本例中,存儲庫位於數據層內部,數據層將定義數據將如何被獲取和管理,所有這些我們很快就會講到,但重要的是,數據層中的存儲庫將實現抽象類,是以它必須符合所謂的契約。是以,讓我們在 VS 代碼中創建一個文件夾結構,域層將有三個子文件夾實體,其中一個是數字小知識實體,它將保存小知識的文本和數字小知識的編號。最後一個文件夾是用例,用例是獲取具體的