Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am developing an Android unit conversion and calculator application in which I have a 3 fragment ViewPager set up and was wondering what would be the best OOP design practice when attempting to use methods over many fragments. Should I set up a centralized calculate method and call it within each fragment?
I currently have each fragment isolated with their calculations, spinner values, and intermediary values. I am also sending a result of a calculation from a fragment back to another fragment through an intent on the Main Activity.
My code currently works, but as I am learning more Java I would like to start piecing together best design practices and efficient code. Thanks for any insight!
If possible, i'd write something like CalculationUtils.java and define every common method inside, as public static, and later call them with CalculationUtils.method1(...)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm looking for a way to thread the ViewModels in a MVVM Architecture, without having to use tasks everywhere.
My ideal solution would be :
1 Application Thread (with the view)
1 Background Thread (with the viewModel)
Message passing between the 2
ViewModels still behave as normal Java Classes w/o Tasks/Service/Platform.runlater in every method
Is there a way to do this without bloating the code ?
This is probably not going to work the way you would like it to work. The view-models normally communicate with the views via bound properties. Therefore the properties of the view-models must always be updated on the application thread.
The proposed JavaFX way of dealing with concurrent background activities is to use Services. But if you don't like that it maybe worth it to have a look here: https://github.com/ReactiveX/RxJavaFX
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to know which is the better implementation of the view on MVP.
For example in small Apps, It's better to use one or two activity's and use as a View the Fragments? or It's better use one Activity for all screens as View without any Fragments?
Whether you should use activity or fragment not actually depends on MVP. This decision should be taken based on your app's requirement. If the app is such that the pages do not have much to share between them and pages are quite unique based design and functionality, you should go for activity. On the other hand, if there are lots of interactions going on between the pages or based on design and functionality lots of similarity is found between the pages, using fragments will be a better option. It will reduce lot of duplicate codes.
One definition of MVP (there are quite a lot) states, that the presenter is an implementation detail of the View. So, MVP per se has no preference for either of Activity or Fragment. You can attach a presenter to both of them equally well and use it to separate business logic from the presentation layer.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So, I just finished my first program, but I haven't use any methods in it, since I'm just beginning to learn how to use them. Here's the original code : http://codepad.org/JiBfJI8Q I started to fractionate it but realised that it would be a method inside another all the way down. Is that actually the way to do it, or did I get the idea wrong?
without having looked at your code:
The general idea of methods is to separate small
portions of code which might be used at multiple other places in your code.
so yes, calling methods from within other methods is a good thing to do.
ideally your so called "composed methods" read out like a little story:
public void transaction(){
openDatabaseConnection();
addRecordsToDatabase();
closeDataseConnection();
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I would like to create a table which is filled by data from DB. I know that it is possible to create a dynamic table using TableLayout but I'm not sure that it's the best solution im my case.
Here is an example of what I want to create(the first table on the page).
I'll give you my inputs on this.
If your data is limited and you are sure to display all of it in a single screen in a presentable manner, then yes, a TableLayout will suffice.
However, in a real world, flexibility counts so you should always consider the possibility that your data may expand in the future. Keeping that in mind, you should use a ListView or a RecyclerView in this case. Define a base layout for each row of your list or recycler view and then connect the data from your database to this view using a suitable adapter.
For starters:
https://developer.android.com/training/material/lists-cards.html
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Say I have a method that is used for opening application with an android app from a sidebar
openApplication(Sidebar s, Context c ... )
and now I want to use this openApplication to open from a Topbar
openApplication(TopBar t, Context c ... )
The function openApplication is very similiar but needs to do little-changes based on Sidebar or TopBar attributes/ members
I dont what to make two different functions that basically do the same thing but different in 2-3 lines of code. What is good practice for approaches like this
I was considering passing a boolean or enum to the function to tell the difference but then I would have lots of if statements in the function for little things. Was also condering making private members _topbar, _sidebar but then if statements again ?
Is there a good practice to generalize functions ? or design pattern out there?
Look at the common interface or superclass that both Topbar and Sidebar share, and use that as the type.