-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Refactor project structure to one single module? #112
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
Comments
Thanks for the mention, @android10! I'll just give my two cents here and bring some points up for discussion so we can hear everyone's ideas about them. That core package Package by feature, then by layer
The other feature packages make sense. A package for the "navigation" feature. A package for the "data retrieval" feature, and so on. These are just a few ideas and are mainly meant to fire up the discussion. I'd be happy to hear anyone's thoughts. If i have so more time, i'll go over the branch in more detail. |
Hey, think about using veripacks in this approach so application flow would go as intendent (view -> domain -> data). |
Hi guys. thanks for mentioning @android10! I will go over the advantages to describe my thoughts as I am as supporter of the 3 modules/layer approach. Scalability: I think that this depends on how the team is structured. For example for a very big organisation there are teams for specific layers/modules in every kind software (mobile/web etc.) . I think that the package by feature makes sense on presentation and domain layer where it's much easier to apply it and maintain it. The data and the core layer must be abstract, independent and must expose only the necessary things which will be used by the upper layers. The data and the core layer must be able to run their tests without any dependency in the domain and the presentation layer. For sure in a 3 modules/layer approach it can be a 4th core module. This is the approach which we are using here also we have a separated core module but not for DI or views. We use it for some tools which we want to be available in every layer. Scope: I think this can be done easily with current implementation also but it needs changes using the DI. I will refer again the Effective Java book and especially the Item 13 Minimize the accessibility of classes and members. This can be done with Dagger2 according to different modules, components and scopes. That's why the Dagger2 give us power. Build System: I think this is not valid as there are plenty of optimisations and techniques which we can apply and boost the performance of the build process. Now for the Drawbacks section I want to note the Dependency with the framework which is very very important. Many Devs use Lastly which you didn't mention guys and I think it's very important is that with this kind of approach we aren't able to run the different layer tests independently in a CI environment and in the development process. With the one module approach it's obvious that I must run every test which it's not efficient. Yes I know you can do it via Android studio (for dev process) but there are different scenarios when I am using a CI and I want to have different kind of build processes. That's all guys, these are my comments :) . So food for thoughts. This kind of discussion would be great to be done in a pub with 🍻 |
I like to have a "feature-structure"... |
Look at point 10 and especially 15 ;-) |
Hi guys, If you look a the current structure, you come across packages as "repository", "interactor", "presenter", ... which indeed contain all related classes. The "repository" packages contains the "UserRepository", the "PhotoRepository", the "WhateverRepository". I think we should split these up by feature. Here's a package tree to clarify it more.
This way, we keep certain features (navigation, caching,...) in their current layer and have the features of what our app actually "does" grouped in their respective packages. |
@Trikke I like your "fart" ;-) |
Nice discussion guys. I see there are mixed feelings around this PR and honestly I don't see any solution better than the other. |
I might not merge this PR for now but I will link this to the articles so people can participate and leave their 2 cents on this approach. |
@android10 in another issue you talked about working on projects at Soundcloud where projects exists within a single module. Is there a difference in setup between those and this PR? Or is the 3-tier module setup something you created because you liked it more, reflecting on your work at Soundcloud? |
The 3 module project was an initiative to completely run away from android, specially on the domain layer which is a pure java project favoring unit tests, since a couple of years ago, it was very difficult to setup robolectric and junit so you had to create a separate module to test another module. (that does not happen anymore fortunately, buy you can check the history of this repo when I got rid of it). As I put in the description, I think 3 modules bring a little bit of overhead and that is the reason why I wanted to start this discussion (plus the other disadvantages I mentioned in the description). I'm not saying our solution at SoundCloud is perfect but wanted some input and thoughts coming from the community). Also we are not using a pure Clean Architecture approach, although is similar. If you are curious about how we work and have a taste of how our app works here are 2 interesting videos: https://www.youtube.com/watch?v=R16OHcZJTno |
Interesting videos to watch, thanks! The first guy talks about a "featurized layers", which i think is something i suggested here as well. I'll look at the second video once i've got some more time. |
I agree with @android10, the 3 modules make us hard to manage. It is quite over engineered. Testing is much more easier now. We can keep dependency rule and layers boundary by training and code review. |
@android10 You wrote that you won't merge this PR. Will be this "all-in-one"-branch also updated in future - or is this effort you made "lost"? |
@Rainer-Lang for now I will keep it open and try to maintain it, since there are mixed feelings and I'm not 100% sure yet. Any idea/feedback/input on how to keep both approaches? |
@android10 very nice presentation by Matthias. |
@android10 Sorry for the delay...life is sometimes hard.... :( For keeping the both synced - I'm sure this could only be done by hard work - every pr/change will have to be done in both. PUH |
How about this? https://codelabs.developers.google.com/codelabs/android-testing/index.html#4
https://github.com/googlesamples/android-architecture |
@Trikke and @android10 , I did try to implement organisation by layer and then by feature. Its incredibly difficult without breaking boundaries. I also integrated Retrofit for the API. Nevertheless, here is a sample project. https://github.com/RowlandOti/Doea |
Hi, I was wondering what could happen with this structure once the Android Instant App get released. |
I don't see what the Instant Apps feature has to do with this Architecture. The first 2 questions of their FAQ are: Do developers need to build two different Android apps now? What Android APIs and functionality can Instant Apps use? |
What I mean is, for the instant build version to be done, would we need to create a separate module for that? I didn't see any sample yet, that's why I'm asking. Anyway if I'm not wrong I remember to have heard something about modules in the IO. |
So what you are asking is information none of us have. There's no sample code from Google, no technical guides or anything. It seems like something in a testing phase with the big developers and there's a mailing list you can subscribe to for updates. You'll have to wait and see how it pans out if they ever release it. Then we'll know how to implement that feature. But going by their FAQ, i imagine it will be just some gradle config and probably a whole lot of checks for features that these Instant Apps can't use. |
I think you could access the testing phase from this link https://docs.google.com/forms/d/1S3MzsMVIlchLCqyNLaFbv64llxWaf90QSeYLeswco90/viewform?fbzx=-652575268842575597 Anyway thank you for the info @Trikke |
What do you do when you have features that are somehow related to each other but at the same time they should be independent? For instance suppose that your app should have a module to manage an Inventory of products and another feature to create Orders. In the Inventory feature you can see a list of products and their details while in the Orders feature you are required to enter de Order details and select items. In order to select the Items for an Order the app needs to show a list of products then the product detail and let the user enter the price and quantity. With the example above, I would like to reuse the Inventory module in the Orders module to display the list of products and their details but how would you recommend to pass the 'selected' product back to the Order module without letting the Inventory module know about the Orders? So basically the applications paths would be:
|
@android10 I think that the problem that I encounter when packaging by feature is when two features share a Use Case. What should we do then? Do we use the one that is already written in Feature A or do we rewrite it in Feature B? Neither feels good. If we reference a UseCase from another package there is no garantee that someone would change it and break the other feature. But if we rewrite it we end up with duplicated code :s |
@kevin-barrientos if their are closely related it probably makes sense merge them into one feature. Or you could create a parent feature that contains a core, feature-a and feature-b package. |
nice talk...first time am here...thanks all for you guidance ... |
Hi guys, I just wanted to give my 2 cents on this. Now we see that So which one to choose? With this approach there is no need to duplicate business or data logic only because in different screens there is common logic and when a screen needs to show a set of features you just need to import the module (domain+data) of each feature you need. I might be completely wrong but I think this is a better approach. |
Hey @DenisBronx that is very interesting. Thanks for sharing. I will definitely check the |
I also have some additional observations: -The domain+data block is not an actual module but a "component", in my approach there would be a |
Hi guys, as you can see I have been working on a single module project structure.
Here is the PR: #103
I'm not saying that I will land it but I do want to start a discussion around it and see pros and cons for either a single module project or multi module project.
The first couple of things that came to my mind:
Advantages:
build.gradle
files for each project (better performance?).Drawbacks:
A few extra eyes are very appreciated, so let's try to find the best way to keep on improving this codebase.
@spirosoik @Trikke @caseykulm I mention you guys since have been collaborating a lot. Thanks! Feel free to involve anyone here 😃
The text was updated successfully, but these errors were encountered: