From the experience of development in java, I learned that it would be more expedient to make a separate class for each action in order to follow the rules of the OOP. But now, starting to learn Android, I have a question. Is it worth doing this in Android development? After all, here and so for each Activity a class is created, but still, when there are so many different buttons, fields, etc. in the Activity, the code in it looks very large and it becomes inconvenient to read. I would like to hear the opinion of knowledgeable people about this.

  • No, this is not necessary. Activiti - the controller of widgets on the screen, its purpose is to process the reactions to widgets - pavlofff

1 answer 1

From the experience of developing in java, I learned that it would be better for each action to make its own separate class

Sometimes it is advisable, sometimes it is redundant. It is very difficult to say something abstractly, it all depends on the specific situation.

Is it worth doing this in Android development?

Again, it all depends on the particular case.

but still, when there are a lot of different buttons, fields, etc. in the Activity, the code in it looks very large and it becomes inconvenient to read.

Manipulations with any View objects should not be carried out somewhere beyond the limits of activation, to which they relate directly - this, at least, complicates reading the code and is fraught with memory leaks .

To customize the views, you can add the void configViews() method to the void configViews() , in which you can group all actions to configure these widgets.

Manipulations with any non- View objects can be put into a separate class, following the OOP concept, but whether you need it or not depends on the specific situation.