?? tiofp documentation - a worked example of using the tiopf.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0074)http://www.techinsite.com.au/tiOPF/Doc/5_AWorkedExampleOfUsingTheTIOPF.htm -->
<HTML><HEAD><TITLE>tiOFP Documentation - A worked example of using the tiOPF</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><!-- InstanceBegin template="/Templates/TechInsite_Template.dwt" codeOutsideHTMLIsLocked="false" --><!-- InstanceBeginEditable name="doctitle" --><!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><LINK
href="tiOFP Documentation - A worked example of using the tiOPF_files/TechInsite.css"
type=text/css rel=stylesheet>
<META content="MSHTML 6.00.3790.1830" name=GENERATOR></HEAD>
<BODY>
<SCRIPT type=text/javascript>function Go(){return}</SCRIPT>
<SCRIPT
src="tiOFP Documentation - A worked example of using the tiOPF_files/MainMenu_TechInsite.js"
type=text/javascript></SCRIPT>
<SCRIPT
src="tiOFP Documentation - A worked example of using the tiOPF_files/HVMenu.js"
type=text/javascript></SCRIPT>
<NOSCRIPT>Your browser does not support script</NOSCRIPT>
<DIV id=Container><IMG height=75 alt=""
src="tiOFP Documentation - A worked example of using the tiOPF_files/Banner01.jpg"
width=600 border=0>
<TABLE cellPadding=5 valign="middle">
<TBODY>
<TR>
<TD>
<DIV id=pageheader1>TechInsite</DIV></TD>
<TD>
<DIV id=pageheader2>Home of the TechInsite Object Persistence
Framework<BR>Melbourne, Australia</DIV></TD></TR></TBODY></TABLE>
<HR>
<TABLE>
<TBODY>
<TR>
<TD>
<DIV id=HMenu style="POSITION: relative"></DIV></TD></TR></TBODY></TABLE><BR>
<HR>
<!-- InstanceBeginEditable name="Page title" -->
<H1>5. A Worked Example of Using the tiOFP </H1><!-- InstanceEndEditable --><!-- InstanceBeginEditable name="Page body" -->
<H2 class=Normal>The aims of this chapter</H2>
<P>In the previous chapters, we have seen how to use the Visitor pattern, along
with the Template Method to map a business object model into a relational
database. We have also developed an abstract business object, and collection
object to descend our concrete classes from. In this chapter, we will build on
what we have covered and create a working application using the TechInsite
object persistence framework.</P>
<P>We shall work through the following steps:</P>
<OL>
<LI>Write a brief use case for the system we will build
<LI>Draw a class diagram of the business object model (using the UML design
tool minUML)
<LI>Design the database schema, and document the mapping between objects and
tables, properties and columns
<LI>Code the business object model
<LI>Write the SQL create script for the database
<LI>Look at alternative BOM – database mapping strategies:<BR>a) Hard code the
SQL<BR>b) Use the tiSQLManager<BR>c) Auto generate the SQL
<LI>Write the GUI and hook it up to the BOM
<LI>Modify the application so it will connect to different databases </LI></OL>
<P>The order that we work through these steps shall be 1 to 5, then we will
implement one of the strategies in 6 so we can write the GUI in 7. We will then
return to 6 and implement the other two strategies before moving on to 8 where
we will implement the swappable database connection layer.</P>
<P>At the end of this chapter we will have build a contact management
application that will seamlessly connect to either Interbase using IBExpress,
Paradox using the BDE or Access using ADO.</P>
<H2>Prerequisites</H2>
<P>This chapter builds on the concepts introduced in chapters 2, 3 and 4 so it
will be a good idea to read these first. It also assumes that you have installed
the tiOPF, details of which are described in chapter 5.</P>
<H2>Application design: The use case</H2>
<P>There are two actors and two use cases in the system: Administrators who are
responsible for maintaining the contact list, and users who will be searching
for a contact by name. These actors may or may not be the same person so a read
only view will be necessary to prevent users from modifying data that only
administrators should have access to. A diagram representing this is shown
below:</P>
<P><IMG height=114
src="tiOFP Documentation - A worked example of using the tiOPF_files/6_AWorkedExampleOfUsingTheTIOPF_clip_image001.gif"
width=427> </P>
<H2>Look and feel</H2>
<P>The application will use a tree view on the left-hand side of the main form
to browse and search for the contacts in the database. Initially, all the
contacts will be loaded when the application starts, but we will probably want
to change as the size of the database grows to provide database level
searching.</P>
<H2>Use case #1 Search for a contact</H2>
<OL>
<LI>Start the application and enough data about each entry in the database
will load to allow a human to navigate.
<LI>Scroll down the tree view and click on the required person – the person’s
details will load and be shown on the right hand side of the application.
</LI></OL>
<H2>Use case #2 Maintain contacts</H2>
<OL>
<LI>Navigate to the contact to be changed as in use case #1, or click insert
to add a new contact.
<LI>Navigate to the part of the contact to be maintained (e.g., name, and
phone number, postal address) and make edits.
<LI>Click save button. </LI></OL>
<H2>The class diagram</H2>
<P>We shall implement the contact management application with 7 classes as shown
in the class diagram below:</P>
<P><IMG height=246
src="tiOFP Documentation - A worked example of using the tiOPF_files/6_AWorkedExampleOfUsingTheTIOPF_clip_image001_0000.gif"
width=576> </P>
<P>These classes have the following purposes:</P>
<TABLE cellSpacing=0 cellPadding=0>
<TBODY>
<TR class=Normal>
<TD vAlign=top width=111>
<P><STRONG>Class </STRONG></P></TD>
<TD vAlign=top width=104>
<P><STRONG>Parent </STRONG></P></TD>
<TD vAlign=top width=369>
<P><STRONG>Description </STRONG></P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TContactMgr</P></TD>
<TD vAlign=top width=104>
<P class=Normal>TPerObjAbs</P></TD>
<TD vAlign=top width=369>
<P>The top of the hierarchy. Initially, this class will just be a holder
for an instance of TPeople, but later we may extend it to contain lookup
list data, and perhaps an instance of TCompanies</P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TPeople</P></TD>
<TD vAlign=top width=104>
<P>TPerObjList</P></TD>
<TD vAlign=top width=369>
<P>A collection of TPeople</P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TPerson</P></TD>
<TD vAlign=top width=104>
<P>TPerObjAbs</P></TD>
<TD vAlign=top width=369>
<P>A person object owned by TPeople. Has published properties for
LastName, FirstName, Title and Initials. Has a property of type TAdrsList
and TEAdrsList.</P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TAdrsList</P></TD>
<TD vAlign=top width=104>
<P>TPerObjList</P></TD>
<TD vAlign=top width=369>
<P>A container for TAdrs objects</P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TEAdrsList</P></TD>
<TD vAlign=top width=104>
<P>TPerObjList</P></TD>
<TD vAlign=top width=369>
<P>A container for TEAdrs objects</P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TAdrs</P></TD>
<TD vAlign=top width=104>
<P>TPerObjAbs</P></TD>
<TD vAlign=top width=369>
<P>Holds a conventional street or post office box address. Has published
properties AdrsType, lines, suburb, state, postcode and country.</P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=111>
<P>TEAdrs</P></TD>
<TD vAlign=top width=104>
<P>TPerObjAbs</P></TD>
<TD vAlign=top width=369>
<P>An electronic address object that belong to the TPerson. Has properties
Address type and address text.</P></TD></TR></TBODY></TABLE>
<H2>The database schema & object – database mapping</A></H2>
<P>We shall store the data modelled by these seven classes in three tables in
the database as shown in the table below:</P>
<TABLE cellSpacing=0 cellPadding=0>
<TBODY>
<TR class=Normal>
<TD vAlign=top width=83>
<P><STRONG>Class </STRONG></P></TD>
<TD vAlign=top width=95>
<P><STRONG>Table </STRONG></P></TD>
<TD vAlign=top width=94>
<P><STRONG>Property </STRONG></P></TD>
<TD vAlign=top width=104>
<P><STRONG>Column </STRONG></P></TD>
<TD vAlign=top width=132>
<P><STRONG>Notes </STRONG></P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P>TPerson</P></TD>
<TD vAlign=top width=95>
<P>Person</P></TD>
<TD vAlign=top width=94>
<P>OID</P></TD>
<TD vAlign=top width=104>
<P>OID</P></TD>
<TD vAlign=top width=132>
<P>Primary key </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>FirstName</P></TD>
<TD vAlign=top width=104>
<P>First_Name </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>LastName</P></TD>
<TD vAlign=top width=104>
<P>Last_Name </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>Title</P></TD>
<TD vAlign=top width=104>
<P>title </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>Initials</P></TD>
<TD vAlign=top width=104>
<P>initials </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>Notes</P></TD>
<TD vAlign=top width=104>
<P>notes </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P>TAdrs</P></TD>
<TD vAlign=top width=95>
<P>Adrs</P></TD>
<TD vAlign=top width=94>
<P>OID</P></TD>
<TD vAlign=top width=104>
<P>oid</P></TD>
<TD vAlign=top width=132>
<P>Primary key </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>Owner.OID</P></TD>
<TD vAlign=top width=104>
<P>owner_oid </P></TD>
<TD vAlign=top width=132>
<P>Foreign key to Person </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>AdrsType</P></TD>
<TD vAlign=top width=104>
<P>lines adrs_type </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
<P>Suburb</P></TD>
<TD vAlign=top width=104>
<P>suburb </P></TD>
<TD vAlign=top width=132>
<P> </P></TD></TR>
<TR class=Normal>
<TD vAlign=top width=83>
<P> </P></TD>
<TD vAlign=top width=95>
<P> </P></TD>
<TD vAlign=top width=94>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -