System design and architecture notes: Key-value pairs used in Architecture Design

Source: Internet
Author: User
Tags map data structure
    1. About meProgramUnderstanding

As a programmer, how do you understand a program? Write this articleArticleWhen I think about the program, I find that my understanding of the program is not the same as that of the textbook. Every time I hear the word "program", I only think of two things:CodeAnd data, and each time you write a program, it is the process of writing code to operate data.

Program Development is similar to cooking. Data is about food, code is about cooking, and software is about cooking. As for how delicious the food is, is it about food or cooking? Well, when I threw out this question, my first reaction was that the food was not good. Of course, the craft was poor. I don't know if other children's shoes thought that way. Think about it seriously. A good dish must be both of the two. Of course, it cannot be ruled out that a certain highlight item can achieve the same effect. However, this situation is not popular, but belongs to a few elites, the same is true for software, and code and data cannot be neglected. Here I want to mention data.

Based on my experience and knowledge (I have never thought too well about the classification standards, so I said my own experience and knowledge), I divided data into two categories: landing data and not landing data.

    1. Landing data: persistent data, which is usually stored on a hard disk or another persistent storage device. For example: images, system logs, data displayed on the page, and data stored in the relational database, there must be a fixed carrier for landing data that will not disappear instantly.
    2. Data not implemented: generally refers to the data stored in memory or network transmission. The data is instantaneous and disappears after use. For example, the request we send to the server in a browser; data read from the database and displayed on the page.

Anyone who has written the program knows that the two types of data operations in the program are very different.

2. Start with the MVC design pattern of javaee

An important contribution of Java is the introduction of the MVC design pattern. MVC should actually read the best in the VCM sequence. V and view, mainly the front-end display page; C and controller, the control layer is mainly used to accept the front-end page data, according to different data calls different business models in the background, at the same time, the data processed by the business model should also be sent to the Controller, and the Controller should be assigned to the corresponding front-end page; m and model, the model layer is responsible for operating the business model. The MVC concept is well expressed:

With the development of the MVC model, the popular architecture is: View (view layer) + controller (also called Action, control layer) + Service (business model layer) + Dao (Data Access Object layer) + The multi-layer structure of the database, such:

 

The red line is the user's request, and the blue line is the server's response to the user's request. The red and blue lines also represent the flow of data transmission at each layer.

No matter the traditional MVC model or the popular multi-layer architecture, data transmitted at each logic layer is not implemented.

In Java projects, we generally transmit JavaBean, which are defined by programmers based on actual business needs. For example, the following typical JavaBean:

 Public   Class User {

Private String name = "";
Private String sex = "";
Private String age = "";
Public String getname (){
Return Name;
}
Public Void Setname (string name ){
This . Name = Name;
}
Public String getsex (){
Return Sex;
}
Public Void Setsex (string sex ){
This . Sex = sex;
}
Public String getage (){
Return Age;
}
Public Void Setage (string age ){
This . Age = age;
}



}

The concept of transmitting JavaBean objects at each logic layer will surely be deeply rooted in the hearts of many Java programmers. At the beginning of a project, programmers will attempt to create JavaBean objects, such as an mapped to database tables, in struts1.2, there is also a page to express the corresponding JavaBean. After so many years of such a JavaBean, now I think, is it the best choice to Use Javabean?

3. nojavabean

I am here to use the definition of nosql, which is now very popular, as the title of the third part of my article. JavaBean has gone deep into the psychology of many Java programmers and even the habits of many programmers. Is it actually so useful? Is it true? Actually not all, I want to list its shortcomings below:

1. Too many JavaBean files. For a Java Enterprise Project, Orm is used to map databases to Java objects. Generally, a table corresponds to a JavaBean. In some special cases, some tables are merged to form a unified JavaBean, if the system has 1000 tables, there will be no less than 1000 JavaBean. In the original struts1.2, there will also be a JavaBean that corresponds to the one-to-one page form fields. As you can imagine, these non-technical Java classes may breed like viruses.

2. JavaBean will enhance the coupling between layers. When the operation ends in each layer, most of the business data will be encapsulated into a JavaBean object, and the JavaBean encapsulated by different businesses is different. MVC is designed for the logic layer decoupling, however, the transmission media contains the business logic. If you encounter changes at the business level, there will be corresponding structural changes between the layers, increasing the maintenance cost.

3. We will maintain at least one data dictionary. In a table in the database, a field named user_name may be changed to username in the JavaBean. Of course, we have a ing model in the Orm, but as data passes through layers, the further the data is from the database, the blurrier the nature of the data, which may lead to misunderstandings for new users and increase the cost of software development and maintenance.

4. This is a drawback I encountered in my actual project. I haven't summarized it into a general defect yet, but I believe there will be similar problems in my shoes. I manage permissions in a project. Because of the sensitivity of some data, we want to grant permissions to datasets. For example, some people can only view the data of the day, while others can only view the first 10 data records of the day, others can only view the data of the last week, and only three fields can be viewed. Because permission management is a task of phase III in this project, our permission design is to be developed on the original system and contains two different projects, one of which is to Use Javabean for transmission media, another method is used. In the end, this JavaBean becomes our nightmare. To make a general solution, we will reconstruct it using JavaBean as the transmission media project, increased the workload.

5. the idea of MVC layering is actually to let professional people do professional things, be good at page-based, and be good at logic-based logic. Project development based on MVC idea is usually horizontally grouped, however, in actual development, no one dared to allocate work like this. The reason is that the media directly transmitted between layers is not uniform.

Since my title is nojavabean and not only JavaBean, it is like nosql that can satisfy SQL database limitations. What technologies can we use to make up for these shortcomings?

The answer is: Key-value pairs.

4. omnipotent map (key-value pairs)

Google's three papers have brought about the cloud era and changed the world with a broad mind. The most important thing here is map (key-Value Pair ), I personally think the key-value mode (Kv later) and array can basically express 90% of the world. In addition, basically all languages support the kV data structure. how powerful the kV structure is, the world is changed by this simple method. (I would like to talk about the role of Kv IN cloud computing storage and computing as a supplement to the topic of this article, but with time constraints, you can refer to relevant materials on your own ).

My alternative data model is to use map as the data transmission medium. The source of this idea is three technologies: mapreduce, ibatis, and JSON. Our center attaches great importance to hadoop technology, we often share hadoop-related technologies here. It sounds like there are all mapreduce, which are map and map. Now our company's projects use ibatis for Orm, and there were a lot of tables at that time, i'm a lazy. Not all ibatis configuration files correspond to JavaBean one-to-one, but a map object is returned. If it is a list query, it is a list <map>. I didn't think this was an unexpected result, because the page data is encapsulated into JSON objects, JSON is actually a key-value pair model. when the data is sent to the action, it is also transferred to map, and all return values are the same, the whole development efficiency has been improved, and the project has fewer JavaBean objects, which is much more refreshing.

Next I will summarize the advantages of map. In the third part of the article, I wrote the shortcomings of JavaBean. These shortcomings are the advantages of map. I will not repeat them here:

1. No matter what technology is, the value of map is uniform: for example, JSON in javascript:

 

 
OBJ. xxx or OBJ [XXX]

Map in Java:

 
Map. Get (XXX) or map. Put (XXX)

Map uses Keys, keys are strings, and can be defined at any time, while JavaBean reads data through defined methods. If map is used, business attributes of transmitted data are enclosed in map, this facilitates operations.

2. Map technology is available in almost all mainstream technologies, so using this data structure as the transmission medium is cross-platform.

3. Map Data StructureAlgorithmIt is very mature, and complex computing is very convenient.

OK, write it here. There are still a lot of things that are not clearly explained. I am too tired to write and will catch the train tomorrow morning. My idea is to hear your opinions, I am a little fascinated by map now. I don't know if it will bring more development convenience for us to transmit data structures such as map on each logic layer. I hope to hear your comments.

    1. My understanding of the program

As a programmer, how do you understand a program? When I wrote this article, I thought carefully and found that my understanding of the program is not the same as that of the textbook. Every time I hear the word "procedure", I only think of two things: code and data, and each time you write a program, it is also the process of writing code to operate data.

Program Development is similar to cooking. Data is about food, code is about cooking, and software is about cooking. As for how delicious the food is, is it about food or cooking? Well, when I threw out this question, my first reaction was that the food was not good. Of course, the craft was poor. I don't know if other children's shoes thought that way. Think about it seriously. A good dish must be both of the two. Of course, it cannot be ruled out that a certain highlight item can achieve the same effect. However, this situation is not popular, but belongs to a few elites, the same is true for software, and code and data cannot be neglected. Here I want to mention data.

Based on my experience and knowledge (I have never thought too well about the classification standards, so I said my own experience and knowledge), I divided data into two categories: landing data and not landing data.

    1. Landing data: persistent data, which is usually stored on a hard disk or another persistent storage device. For example: images, system logs, data displayed on the page, and data stored in the relational database, there must be a fixed carrier for landing data that will not disappear instantly.
    2. Data not implemented: generally refers to the data stored in memory or network transmission. The data is instantaneous and disappears after use. For example, the request we send to the server in a browser; data read from the database and displayed on the page.

Anyone who has written the program knows that the two types of data operations in the program are very different.

2. Start with the MVC design pattern of javaee

An important contribution of Java is the introduction of the MVC design pattern. MVC should actually read the best in the VCM sequence. V and view, mainly the front-end display page; C and controller, the control layer is mainly used to accept the front-end page data, according to different data calls different business models in the background, at the same time, the data processed by the business model should also be sent to the Controller, and the Controller should be assigned to the corresponding front-end page; m and model, the model layer is responsible for operating the business model. The MVC concept is well expressed:

With the development of the MVC model, the popular architecture is: View (view layer) + controller (also called Action, control layer) + Service (business model layer) + Dao (Data Access Object layer) + The multi-layer structure of the database, such:

 

The red line is the user's request, and the blue line is the server's response to the user's request. The red and blue lines also represent the flow of data transmission at each layer.

No matter the traditional MVC model or the popular multi-layer architecture, data transmitted at each logic layer is not implemented.

In Java projects, we generally transmit JavaBean, which are defined by programmers based on actual business needs. For example, the following typical JavaBean:

 Public   Class User {

Private String name = "";
Private String sex = "";
Private String age = "";
Public String getname (){
Return Name;
}
Public Void Setname (string name ){
This . Name = Name;
}
Public String getsex (){
Return Sex;
}
Public Void Setsex (string sex ){
This . Sex = sex;
}
Public String getage (){
Return Age;
}
Public Void Setage (string age ){
This . Age = age;
}



}

The concept of transmitting JavaBean objects at each logic layer will surely be deeply rooted in the hearts of many Java programmers. At the beginning of a project, programmers will attempt to create JavaBean objects, such as an mapped to database tables, in struts1.2, there is also a page to express the corresponding JavaBean. After so many years of such a JavaBean, now I think, is it the best choice to Use Javabean?

3. nojavabean

I am here to use the definition of nosql, which is now very popular, as the title of the third part of my article. JavaBean has gone deep into the psychology of many Java programmers and even the habits of many programmers. Is it actually so useful? Is it true? Actually not all, I want to list its shortcomings below:

1. Too many JavaBean files. For a Java Enterprise Project, Orm is used to map databases to Java objects. Generally, a table corresponds to a JavaBean. In some special cases, some tables are merged to form a unified JavaBean, if the system has 1000 tables, there will be no less than 1000 JavaBean. In the original struts1.2, there will also be a JavaBean that corresponds to the one-to-one page form fields. As you can imagine, these non-technical Java classes may breed like viruses.

2. JavaBean will enhance the coupling between layers. When the operation ends in each layer, most of the business data will be encapsulated into a JavaBean object, and the JavaBean encapsulated by different businesses is different. MVC is designed for the logic layer decoupling, however, the transmission media contains the business logic. If you encounter changes at the business level, there will be corresponding structural changes between the layers, increasing the maintenance cost.

3. We will maintain at least one data dictionary. In a table in the database, a field named user_name may be changed to username in the JavaBean. Of course, we have a ing model in the Orm, but as data passes through layers, the further the data is from the database, the blurrier the nature of the data, which may lead to misunderstandings for new users and increase the cost of software development and maintenance.

4. This is a drawback I encountered in my actual project. I haven't summarized it into a general defect yet, but I believe there will be similar problems in my shoes. I manage permissions in a project. Because of the sensitivity of some data, we want to grant permissions to datasets. For example, some people can only view the data of the day, while others can only view the first 10 data records of the day, others can only view the data of the last week, and only three fields can be viewed. Because permission management is a task of phase III in this project, our permission design is to be developed on the original system and contains two different projects, one of which is to Use Javabean for transmission media, another method is used. In the end, this JavaBean becomes our nightmare. To make a general solution, we will reconstruct it using JavaBean as the transmission media project, increased the workload.

5. the idea of MVC layering is actually to let professional people do professional things, be good at page-based, and be good at logic-based logic. Project development based on MVC idea is usually horizontally grouped, however, in actual development, no one dared to allocate work like this. The reason is that the media directly transmitted between layers is not uniform.

Since my title is nojavabean and not only JavaBean, it is like nosql that can satisfy SQL database limitations. What technologies can we use to make up for these shortcomings?

The answer is: Key-value pairs.

4. omnipotent map (key-value pairs)

Google's three papers have brought about the cloud era and changed the world with a broad mind. The most important thing here is map (key-Value Pair ), I personally think the key-value mode (Kv later) and array can basically express 90% of the world. In addition, basically all languages support the kV data structure. how powerful the kV structure is, the world is changed by this simple method. (I would like to talk about the role of Kv IN cloud computing storage and computing as a supplement to the topic of this article, but with time constraints, you can refer to relevant materials on your own ).

My alternative data model is to use map as the data transmission medium. The source of this idea is three technologies: mapreduce, ibatis, and JSON. Our center attaches great importance to hadoop technology, we often share hadoop-related technologies here. It sounds like there are all mapreduce, which are map and map. Now our company's projects use ibatis for Orm, and there were a lot of tables at that time, i'm a lazy. Not all ibatis configuration files correspond to JavaBean one-to-one, but a map object is returned. If it is a list query, it is a list <map>. I didn't think this was an unexpected result, because the page data is encapsulated into JSON objects, JSON is actually a key-value pair model. when the data is sent to the action, it is also transferred to map, and all return values are the same, the whole development efficiency has been improved, and the project has fewer JavaBean objects, which is much more refreshing.

Next I will summarize the advantages of map. In the third part of the article, I wrote the shortcomings of JavaBean. These shortcomings are the advantages of map. I will not repeat them here:

1. No matter what technology is, the value of map is uniform: for example, JSON in javascript:

 

 
OBJ. xxx or OBJ [XXX]

Map in Java:

 
Map. Get (XXX) or map. Put (XXX)

Map uses Keys, keys are strings, and can be defined at any time, while JavaBean reads data through defined methods. If map is used, business attributes of transmitted data are enclosed in map, this facilitates operations.

2. Map technology is available in almost all mainstream technologies, so using this data structure as the transmission medium is cross-platform.

3. Map Data Structure algorithms are mature, making complex computing very convenient.

OK, let's write it here. There are still many things that are not clearly explained. I am too tired to write and will catch the train tomorrow morning. I just want to hear your opinions on this idea, I am a little fascinated by map now. I don't know if it will bring more development convenience for us to transmit data structures such as map on each logic layer. I hope to hear your comments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.