Best practices to improve project maintenance

Overview

There are a few recommended practices to improve the organization, maintenance, and performance, and consequently loading your application. Some of them are very basic, like creating a class apart to store the colors used in the application and other more complex as working with loading images that are pulled from an external bank. In this chapter we will learn about these recommendations.

You can download the Material Templates project, which contains all the recommendations below.

Colors

In the development of any application it is essential to have a design to prototype the user interfaces. It turns out that when the developer takes these prototypes and starts to develop, it often ends up adding these colors in the UI classes themselves, which makes it difficult to maintain this code.

you will find free website recommendations for screen prototyping in the part of references in the last topic of this chapter.

Now let's say you have an update to your application and the background color of the APP has changed. If your project has 2 or 3 screens, is it relatively quick to change these colors but if it is a more robust design of 15 screens? The developer would have to quit by changing the background color 15 times.

Thinking about this, TotalCross recommends that you create a class named Colors and create constants for each color that you will need to use in the application, and preferably with suggestive names such as BACKGROUND. The name of the constants must always be in upper case. Here is the standard suggested by TotalCross, feel free to adapt to the needs of your project.

The names we attributed to the contenders were not by chance but rather due to the Color Material standard. You can generate each of these colors and better understand this pattern through Material Color Tools. With this Material tool you select the primary and secondary color of your project and it already generates the application's color palette and font color.

We also provide the source code for you to download and adapt for the project. Just click here.

Images

To facilitate code maintenance, it is also recommended that all images be instantiated in a separate class called Images and only be called in the interface classes.

Images class example:

Using Images.class:

Fonts

As with colors and images, it happens when we are going to edit the fonts and here the problem is even worse, because we still have to stick to the size of fonts, colors and type.

So we advised that before the developer can already take with Design all these details to pass through a class with everything custom, as in the example below:

to apply this class:

Material Constants

The Material recommends a series of size and spacing patterns, so it is ideal to create a class within the useful package and assigning these patterns to the constants, as in the example below:

to apply this class:

References

Last updated

Was this helpful?