When we have constructed the back-end for REST API, many people have used the Spring framework since the Spring framework has been revealed. So, now, Java has been the Spring Framework, and Spring Framework has just been the Java. Unlike the past, the part of technologically concentrating on things we have to do has been more reduced than before into the business logic. From this project, I will try to make the framework of the back-end using the servlet on the tomcat. A purpose I am going to try is to study for the (OOP)Object-Oriented-Programming and the Design Pattern. At first, we need how to run the servlet.

The code for the servlet basically consists of like above. They have a life-cycle which has the functions that are init(), service(), destroy(). Also, they provide us the way to deal with the HTTP method which are doGet(), doPost(), doPut() and doDelete() more and more. Even though they give us the various ways to deal with the HTTP method, in order to pack the common codes, I am going to control the all the data within the life-cycle.

init(): We will locate the functions to initialize the system.
service(): Whenever the server is requested from the client, all the data client requests reach to the function that is service(). So, this function would be the important point.
destroy(): This is the function to close the server. If this server handles threads, we should de-allocate the threads in here.

This framework has basically been constructed with the two part. One is to handle the servlet, and the other is to handle the business logic.

pic1

  1. ServletManagement.class: This class would consist with the singletone-pattern, and this has a role as handling the data which is requested from the client.
  2. AbstractEngine.class: As this is an abstract class, this class would consist with the stratagy-pattern, and this class has a role as the functions packing the codes for the common task such as the security, the logging, and another various tasks.

While developing the framework, sometimes, the used patterns could be changed depending on the situation or added. And, in the future, for handling the database, I am going to use the Abstract Factory Pattern. The specific things are going to be mentioned in the next article.