Android declarative programming of client-server applications

Declarative programming can significantly increase the productivity of programmers. In particular, the DePro library offered to your attention when programming client-server applications provides a productivity increase of 3-5 times compared to imperative languages ​​such as, for example, java, kotlin.


The client-server application class is large enough. It includes such types of applications as: m-commerce, P2P trade, services, banks and finance, travel, instant messengers and social networks, fitness and health, etc.


This acceleration is due to the fact that in declarative programming describe only β€œWHAT should I get?”, And not β€œHOW to do this?”.


To illustrate the differences between declarative and imperative programming, consider the following simple example.


In the activity shown in the figure, there is a fragment (circled by a red line).


image

The markup for this fragment is simple; there is only a RecyclerView with id recycler. The markup for list items is in the item.xml file. Data is located at . The names (id) of the markup elements matches the corresponding names in the data coming from the server.


The programming of the functionality of this fragment can be based on various technologies (templates). We use one of the most common (MVP).


To do this, we need to create the following classes.


Item - describes all the variables that come from the server and the corresponding getters and setters.


Adapter - descendant of RecyclerView.Adapter. The constructor receives data received from a server of type List. There are also three, generally simple, methods: getItemCount - indicates the number of elements in the list; onCreateViewHolder - inflatit View from the item.xml file and creates MyHolder based on it; onBindViewHolder - reads the desired item in the list and puts the data in MyHolder (as a result, they are displayed on the screen). In addition, there is a MyHolder class which describes all the variables in which data will be entered.

Presenter β€” RxJava Retrofit. URL. iView ( MyFragment).


iView – MyFragment.


MyFragment – Fragment. . ( List.) , . , , , .

. , . β€” . URL, RecyclerView item.xml.


β€” , , . , :


recycler(URL, R.id.recycler, R.layout.item);

DePro. , :


component(TC.RECYCLER, model(URL), view(R.id.recycler, R.layout.item_news))

component – ; TC.RECYCLER – ( RecyclerView); model(URL) – , URL; view id recycler- .


, .


DePro . (, , , ...) .


. :


activity( , id )


: activity(β€œsplash”, R.layout.activity_splash)
.


: fragment(β€œauth_phone”, R.layout.fragment_auth_phone)


. MVP.


:


.component(TYPE, model(...), view(...), navigator(...))

TYPE β€” , SPINNER, DRAWER, RECYCLER, MENU, MAP, PAGER .. model(...) . , , URL. view(...) , . navigator(...) . , navigator(start(R.id.video, YOUTUBE)) , R.id.video YOUTUBE. navigator- .


, :


 activity(String name, int layoutId)
        .component(TYPE, model(...), view(...), navigator(...))
        . . .
        .component(TYPE, model(...), view(...), navigator(...));

5 β€” 10 .


DePro :


  • java (SLOC) 40-50 .
  • ( XML β€” ) 15 β€” 20 .
  • ( XML β€” ) 3 β€” 5 .
  • 2 β€” 3 .

. Github.


In the next article we will describe the full cycle of application development using the DePro library.


All Articles