What design pattern can you use to complete multiple steps?

I am developing an Android app and it requires a few steps registration process. Since the amount of data I need to collect is large, I created one activity and another chunk for each step. For example, in the first stage / fragment, the user must provide basic information (name, gender, email address), in the information of the second stage / fragment of education (university, degree, dates of participation) and in the final information of the experience of the step / fragment (companies, name, dates ). Once the user has followed all the steps correctly, I send all the information in one JSON request to my web service.

My question is, what would be the design or design that better models this problem in an elegant, readable and testable way ?. The approach I am currently using, which I think is not good and could potentially create a memory leak in the application, is:

    class Registration {

        // Contains basic user information such as name, gender, etc
        private User user; 

        // Each Education instance contains info such as university, degree, etc 
        private List<Education> studies; 

        // Each Experience instance contains info such as company name, title, etc
        private List<Experience> workExperience;

        private static Registration currentRegistration;

        public static Registration getCurrent() {
            if (currentRegistration == null) {
                currentRegistration = new Registration();
            }
            return currentRegistration;
        }

        /* There are getter and setter methods for each field */
    }

      

As you can see, I have created a registration class with the required fields and a static reference instance that represents the current registration that is provided via the getCurrent method to each fragment that calls it from the OnCreate method and the set of information from this step thought about the appropriate setup method. When the user has entered all the data, I convert this POJO to JSON and make a network request.

Another approach might be to pass a registration instance from Fragment A to B, for which I would need to implement a serializable interface, but I don't like this approach.

The Builder and JavaBean models came to my mind, but I find them more appropriate when I have to initialize an object in a single block expression. Any advice on how to properly simulate this issue? :)

+3


source to share


1 answer


You are too complicated.

I've done this type of implementation before, but it's actually pretty common in terms of registration implementation. I'm not sure if there are any better options out there, I've seen quite a few different ones, but they all fail when it comes to simplicity, compared to how I usually do it:



  • Expand the elective selection group. Typically a scrollview is to create an xml layout and inflate it into a custom view group.
  • In the specified xml add another view group containing each registration step and set visibility to delete.
  • On each registration page, add a button to go to the next.
  • In your custom view group, make sure you are dealing with the next button by confirming the details first.
  • When the user reaches the end of the registration steps, you can simply fetch all the data from the respective fields (e.g. passwordView.getText (). ToString ()) and you can do so with the confidence that you will not receive any null pointers or surprises as you checked all the data at different stages.
  • Bonus points if you add page change view animation.

KISS

0


source







All Articles