-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layer for Managers and Services that require Android Context #151
Comments
@Trikke thank you for answer I have already read this posts. I feel that your Infrastructure layer is the same idea as mine. P.S. Please write me a letter crospdevel@gmail.com |
Well, you are getting the hang of the general idea of it! A few remarks : On any specific platform (iOS,Android,Windows,..) you'll always be stuck with a framework that interfaces with everything on the platform, from UI to Networking to Data Access. The point of an architecture is that we create an idea that works for al those platforms with minimal effort. Because all that stuff like location, gcm, ... doesn't have anything to do with data that is important in your app, it doesn't belong in the Data layer but needs a seperate layer. A lot of people make the mistake of just copying this example repo and start putting everything in the Data layer. Only put data in the Data layer that is important to your app So, like you said, an Infrastructure layer to handle platform services and reside on the same "level" as the Data layer, seen below. You can even see that the above image contains "external services" and "devices" on that outer level, which is what you are talking about. |
@Trikke thank you for complete answer. I got an idea. One more thing I am interested in. So my question is, how What do you think about this ? Thanks. |
Thanks a lot man. You are really good at architecture.
Consider that UI , Data and Infrastructure layer will be on the same layer (ring outermost) based on this architecture. And in the middle will be One thing I am worrying about is that there are three layers dependent on platform (UI, Infrastructure, Data) is it okay ? I would be grateful for your thoughts. |
Yeah, that's true, it's a more traditional diagram, i was just using it to show that there is also stuff that applies to all "layers". Things like Security isn't something you can just put in one layer and keep it there. It's going to be present in all "layers". In general, your idea of data flow seems correct, so stick with that. From an architectural standpoint, keep the following in mind :
On the point of "depending on a platform": you'll always be writing platform specific code. Doesn't matter if it is Java, Android, or iOS. The choice of platform depends on which machines you'll want to run your app. So now you're writing an Android specific app, so it must know about the Android platform. You can only abstract so much before it becomes ridiculous :) |
@Trikke thanks again. It's pleasure for me to discuss such topic with you. |
No problem, i'm happy to help people curious to learn :) So yes, the business/domain layer is the core of your app. It's also the central part of the diagram of Clean Architecture. The domain layer operates with interfaces to connect to the outer layers. But it can also have concrete implementations for it's business logic. Like your example, you can have a concrete Factory that takes 2 data entities and create a new one to be passed to Presentation. So don't think that the domain layer only exists of Use Cases. Here's an extract about this
Rule of thumb is that if i ask you to see what your app does, you only need to show the domain layer to me. If i wanted to then see how you are doing everything around that, i'd need the rest of the layers. And yes, Security is something that is represented differently in each layer, but is present in all. This is why it's a cross cutting concern. Please keep up on reading on these matters, even other stuff then Clean Architecture, there's always something to be learned. |
@Trikke thanks again, this is really good stuff to dive deep into. I always like more architectural approaches rather than feature-driven. I am going to refactor my application completely according to |
@CROSP : Anything from Uncle Bob (like his articles 1, 2). There's also a few youtube videos from talks of his. |
@Trikke |
@Trikke Kudos man for all the light shaded on this and other discussions. Just something else to keep in mind when it comes to dealing with android components:
I do not want my domain logic to know anything about any strong dependency with the framework. |
@android10 thank you for answer. Do you mean that we should use wrappers around framework components anyway. It will include some specific features like As suggested in Uncle Bob's book But I have one question is it ok if For example I have interface that should be implemented on outer So in my Am I right ? Or it would be better to initiate communication between Please share your thoughts. |
You were right with your first suggestion. The Data Layer is just for storing data that is central to your app. It's on the same "level" in Clean architecture as the Infrastructure Layer, so you don't call it through the Data Layer. |
@Trikke thanks again for your response. what about previous picture, does that make any sense ? Or this is not right ? |
Seems about right.
The same discussion went on in here, i hope you'll find some more useful info in there. |
@Trikke thanks, again, I am still finding a lot of new to learn about this architecture. I have just realised one important thing, with the help of your explanation from adjacent topic you provided. One weird thing for me and I can guess for other developers is dependency rule. It seems according to the @android10 articles pretty the same as Lower layer should know nothing about upper layer. And in our case it seems for me that
Please explain this question. |
I have just played a little bit with @android10 project and logged data flow to make it more clear.
So it seems that it is true about violating Please share your thoughts and explanation |
Hey @CROSP , it seems you're confusing the flow of data with dependencies. In the linked discussion above there was already an explanation about this. See this post and then this other post for the entire explanation. The amount of love those post got seem to indicate they explained this issue well. |
@Trikke , thanks, exactly, I have just looked more precisely to the dependencies and it seems that I got it. |
@Trikke I followed your Infrastructure idea. I put AlarmManager, Log, Receiver, Service, AudioManager etc to the Infrastructure layer. Is this OK? https://github.com/enuoCM/DE-MVP-Clean/tree/master/app/src/main/java/com/xixicm/de/infrastructure |
Hi, I am trying to migrate to
Clean Architecture
.I have application which is made in standard way, I tried to decouple, but still a lot of stuff happens in
Activities
andFragments
.Example is quite simple, mostly applications are much more complex so it is much harder to decouple all highly coupled components inside application.
I have just faced with one problem is Managers and Services that requires
ApplicationContext
orActivityContext
.For example I have
LocationManager
which is responsible for getting location, but it requires context, at least to getService
and to listen to lifecycle ofActivity
.I think this manager could go to
Data
layer, but this is undesirable dependency.I really don't want to put this login into presentation layer. I firmly believe that
Presentation
layer should be just UI and ONLY UI nothing more, unfortunatelyAndroid SDK
is build in a way that we haveGod Object
-Activity
but I still wanna to get rid of anything except use cases inPresentation
layer.I see some ways how this can be solved :
Service
orLifecycle
layer and make it tight to context lifecycle, also in order to keep things abstract interface with common lifecycle methods can be created (onCreate
,onDestroy
...)and injected via dependency injection tool like our beloved
Dagger 2
Android
dependency to some layer. Presentation layer is already coupled toAndroid Context
, but again UI should be UI nothing more, consume, update, and request data throughUse cases
from domain layer.Furthermore one important thing to note that
LocationManager
is great example of publisher/subscriber pattern so it can be easily adopted toRxJava
.All things considered, I would be grateful for any thoughts, advice on this problem.
The text was updated successfully, but these errors were encountered: