H-DTO mode (one)

xiaoxiao2021-03-06  88

Foreword

I hope that the accumulation of my design and experience can give you some help from your design or development work. Let's first look at the meaning of the title: H represents: Hash (hash table), is the foundation concept of this article DTO representative: Data transfer objects, such objects need to be used in most applications, the delivery, disconnection, and operation of data may be compared, but the application of the control flow and data stream is implemented. Design ideas is more clear and more popular. Patterns: Mode is a combination of concepts and experiences and constitutes ideas. Every time we say mode, we will think of "Design mode: can be used for object-oriented software" (Design Patterns: Elements of Reusable Object-Oriented SOFTWARE) The 23 design patterns described in the book, and the roots have found that its earlier source begins with Christopher Alexander's "Pattern Language). This is This book is a generation of architects, but there is a very far-reaching influence in the computer science community, and the word proposed in the article has been widely referenced, and it is far beyond the original The field of field has become a universality principle that many people have been pursuing. The definition of the model concept in the book is: a problem solution under a scenario, if the environment is similar, then the solution to the problem can be duplicated, and the application can be duplicated is the reasons and value they exist. The author Martin Fowler, the author of the analysis mode, believes that the model is a kind of thinking, which has been applied to a practical environment and may apply to other environments. (A pattern is an idea That Has BEEN USEful in One Practical Context and Will Probably Be Useful in others.)

1 Overview

During a large-scale business application, designers rack their brains and always want to design the system more in line with requirements, more scalability and advanced. But this is part of it, that is, how the designer has a better design system still requires a lot of mature technology support. It is the accumulation of others, and the full use of available, mature design technology is also system design. A very important part of the process.

The purpose of this article is to introduce a pattern of database transmission design. Its source is a basic model that I have summed up after some system development of foreign countries. I summed up this design, form a basic DTO mode, and constantly Modification (there is no copyright issue). I think the time has arrived, and it can be made public. But I still have a little more care before writing this article, worried that the design I have to describe is not a very good design, so that I have a one-way explanation of a problem, and what H -DTO, and also involves the pattern, I don't want to go again. Later I thought, I am just a shallow developer, and the time empty in hand does not work in the hand.

Although this article implements the design process with Java, it is supported for supporting object-oriented environments, because the Hash table is a basic concept in mathematics and computer, and is also a common data organization and expression in the data structure, as long as you Language environments can support object-oriented and haveh or similar to this design.

The objective achievement is to implement the effective transmission and management of the inter-hierarchical (such as the control layer and the model layer, representation layer and control layer) of the MVC mode, between the objects (such as a control class, and a display page) data. Effective transmission and management; It can combine the effective transfer of data to achieve data in conjunction with session; data rational organization and distribution can be achieved in ordinary applications. 2, simple test class analysis

The following table is a test class for H-DTO mode, it is very simple, but you can look carefully, and those objects are more distinctive. We analyze the entrance through a test class.

TestformData.java

/ *

* Created on 2004-7-2 by Jem.lee

* TestformData.java is a part of com.test

* All Rights Reserved.

* CopyRight (C) 2004. Jem

* /

Package com.test;

Import cn.bs.common.transdata.transformdata;

Import cn.bs.common.transdata.transformtable;

/ **

*

* History

* 2004-7-2

22:46:54

Created by Jem.lee

*

* Purpose

* Test H-DTO mode

*

* /

Public class testformdata {

Public static void main (string [] args) throws exception {

/ / State TransformData object

Transformdata sessdata = new transformdata ();

/ / Place data to TransformData objects (SESDATA)

Seesdata.putfieldValueo ("Test1", "Test1Value");

Seesdata.putfieldValueo ("Test2", "Test2Value";

Seesdata.putfieldValueo ("Test3", "Test3Value";

Seesdata.putfieldValueo ("Test4", "Test4Value";

// Net data from the TransformData object (SESDATA)

System.out.println (SessData.GetfieldValue ("Test1"));

System.out.println (SessData.GetfieldValue ("Test2"));

System.out.println (SessData.GetfieldValue ("Test3"));

System.out.println (SessData.GetfieldValue ("Test4"));

/ / Add a table to TransformData

TransformTable Table = SESDATA.ADDTABLE ("MyTable");

For (int i = 0; i <10; i ) {// 10 rows

/ / Add a record to the table

TransformData Data = Table.Add (); // 5 Counlums

// Add Field to the record, and set the value

Data.putfieldValueo ("TableCoun1", "01");

Data.putfieldValueo ("TableCoun2", "02"); Data.putfieldValueo ("TableCoun3", "03");

Data.putfieldValueo ("TableCoun4", "04");

Data.putfieldValueo ("TableCoun5", "05");

}

System.out.println ("----------------- Table1 ----------------------" );

For (int i = 0; i <10; i ) {

// Get a record from the table

TransformData REC = Table.get (i);

// Get the value of each Field record

System.out.print (Rec.GetfieldFromName ("TableCoun1"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("TableCoun2"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("TableCoun3"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("TableCoun4"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("TableCoun5"). GetValue ());

System.out.println ("|");

}

TransformTable Table2 = NULL;

INT TABLESIZE = 0;

/ / Add a table to the TransformData object,

/ / And determine if the table exists, if it exists, the object of the table is obtained, otherwise the table is created.

Try {

Table2 = sessdata.addtable ("myTable");

} catch (exception ex) {

Table2 = sessdata.gettable ("MyTable");

TableSize = Table2.size ();

}

For (int i = 0; i

TransformData Data = NULL;

/ / Add records to the table and determine if the record exists.

// If there is, you get the object of the record, otherwise create a record

Try {

Data = Table2.Add (); // 5 Counlums

} catch (exception ex) {

Data = Table2.Get (i);

}

Data.putfieldValueo ("Table2coun1", "01");

Data.putfieldValueo ("Table2Coun2", "02");

Data.putfieldValueo ("Table2Coun3", "03");

Data.putfieldValueo ("Table2Coun4", "04"); Data.PutfieldValueo ("Table2coun5", "05");

}

System.out.println ("-------------- TABLE2 --------------------");

For (int i = 10; i <20; i ) {

TransformData REC = Table2.Get (i);

System.out.print (Rec.GetfieldFromName ("Table2Coun1"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("Table2coun2"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("Table2Coun3"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("Table2coun4"). GetValue ());

System.out.print ("|");

System.out.print (Rec.GetfieldFromName ("Table2Coun5"). GetValue ());

System.out.println ("|");

}

}

}

The result is:

Test1Value

Test2Value

Test3Value

Test4Value

--------------------------------------------------- ---

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

01 | 02 | 03 | 04 | 05 |

Through the comments in the document, you can understand that the entire file is used to use two main objects:

Import cn.bs.common.transdata.transformdata;

Import cn.bs.common.transdata.transformtable;

This is the main member of the H-DTO, one is a load data object, one is a table object. The relationship between them is:

TransformData may contain multiple TransformTable

TransformTable may contain multiple TransformData

It seems that there is no rule, but you will know how to look at the program carefully:

TransformData is the application's entrance as a total data object, which holds multiple tables (TransformTable) and multiple field (Transformfield), which can create records (TransformRecord), recorded by transformdata, so TransformData and TransformRecord An inherent connection. The following will be mentioned later. He mentioned in this article: TransformData, TransformTable, Transformfield, TransformRecord constitutes the main branches of the H-DTO.

3, UML design

The UML type model of the H-DTO is described below, indicating the joint relationship and design ideas between them. I believe that through the UML type model, most developers have already understood what is going on, even can see itself to make a thing.

Classdiaram

ComponentDiagram

The first part introduces here, the second part will introduce how to implement these designs on the Java platform. I hope you have a lot of letter to explore design.

转载请注明原文地址:https://www.9cbs.com/read-106924.html

New Post(0)