小牛电子书 > 其他电子书 > VB2008从入门到精通(PDF格式英文版) >

第22章

VB2008从入门到精通(PDF格式英文版)-第22章

小说: VB2008从入门到精通(PDF格式英文版) 字数: 每页3500字

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!




                  bottom…up。 



               o  Within an architecture; individual pieces are called ponents; and they fit together to  

                  create a plete application。  



               o  You write tests because you cannot verify the functionality of a ponent based on its  

                  identifier; parameters; or return value。 



               o  When implementing ponents; you develop tests before; during; and after writing  

                  the source code。 



               o  A test is a piece of source code that calls a ponent using targeted input data; and the  

                  results from the ponent are verified with targeted responses。 If the results do not  

                  match the targeted responses; the ponent has failed。 



               o  The CLR offers many different data types; with the major distinction being between  

                  value and reference types。 



               o  The CLR has many different number types; but all number types are value types。 



               o  Numbers can overflow or underflow。 You should activate a piler setting to make  

                  sure that the CLR will catch those situations。  



               o  When deciding on a specific number type; a large part of the decision is based on how  

                  much precision is desired。 



           Some Things for You to Do 



          The following are some things to consider related to what you’ve learned in this chapter: 



                1。 When you write code; how should you organize your code? For example; do you enforce  

                   certain naming conventions for your classes? Do you enforce the use of code ments? 



                2。 In the development munity; there is a discussion of whether organization of your  

                   software should involve formal structures or should be ad hoc。 Think about how software  

                   should be organized。 



                3。 In general; how would you test whether or not a ponent that uses a database worked  

                   properly? Outline the process with bulleted points。 


…………………………………………………………Page 71……………………………………………………………

                                 CH A PT E R   2   ■    L E A R N I N G   A B OU T   。 N E T  N U M B E R   AN D   V A L U E   T Y P E S  49 



4。  In general; how would you test the correctness of writing data to a file? To help under

    stand the nature of the problem; how do you know that an operating system manipulates  

    files properly? 



5。  If the CLR did not provide for a mechanism to catch overflow and underflow conditions;  

    how would you ensure that overflow and underflow didn’t happen? 



6。  For a Pentium CPU (32 bits); which number type would result in the fastest calculations? 



7。  In this chapter’s example; the class Operations is designed to perform arithmetic using  

    the Double type。 How would you change this so that the calculations are generic and  

    don’t rely on the Double type? 


…………………………………………………………Page 72……………………………………………………………


…………………………………………………………Page 73……………………………………………………………

C  H  A  P  T  E  R     3 



■ ■ ■ 



Learning About String  

 Manipulations  



In the previous chapter; you learned the basics of how data is stored and managed by ;  

including the difference between value and reference types。  has three major data types:  

number…related; custom…defined; and String。 The previous chapter focused on the number

related types。 This chapter will focus on the String type。  

     As you’ll learn in this chapter; the String type has some special characteristics。 If you were  

to look at the bits and bytes of the String type; you would not realize that they were letters。 In  

an abstract description; a String type is a number type with a special grammar。 Since a puter  

understands only numbers; it uses lookup tables that map a set of letters to a set of numbers。 

     The example in this chapter is a multilingual translation program。 The translation program  

will not be sophisticated; nor will it be capable of much。 However; it will illustrate many of the  

issues that you will be confronted with when working with strings。 



Organizing the Translation Application 



As emphasized in the previous chapter; the first step in developing an application is to get  

organized。 We need to understand and define the features of the sample application we are  

going to develop。 The multilingual translation program will implement the following features: 



    o  Translate greetings into three different languages: French; German; and English。 



    o  Convert numbers into the three different languages。 



    o  Convert a date into the three different languages。 



     From a feature perspective; the first feature is logical; but the second and third features are  

not as obvious。 We generally think of translation as translating one word to another word(s)。  

Yet; languages also can represent numbers and dates in different ways。 Translation will mean  

two things: translate a word from one language to another; and translate a number or date  

from one language to another。 

     As in Chapter 2; we’ll create the solution as ponents with three pieces: a Windows  

application; a testing console application; and a class library。 After you have created each of the  

projects; your workspace should look like Figure 3…1。 Remember to add a reference to the  



                                                                                                            51 


…………………………………………………………Page 74……………………………………………………………

52         CH AP T E R   3   ■    L E A R N IN G   AB OU T   ST R I N G   M A N I P U L AT IO N S   



           LanguageTranslator class library (right…click TestLanguageTranslator and choose Add Reference  

            Projects  LanguageTranslator)。 Also remember to set TestLanguageTranslator as the  

           startup project。 



           Figure 3…1。 Structure of projects for the translation application in Visual Basic Express  

           Solution Explorer 



           Building the Translator Application 



           The translation application; like the calculator application example in the previous chapter; is  

           built in pieces: the class library that performs translations based on data delivered by the user  

           interface; the tests; and the user interface。 The individual pieces are ponents that can be fit  

           together like a jigsaw puzzle to create an application。  



           ■Note  ponents are a core part of your development toolbox。 As you will see throughout the book;  

           ponents allow you to reuse and modularize functionality。 ponents result in applications that are main

           tainable and extendable。 Of course; there are limits; and the advantages are not automatic。 You will need to  

           properly design your application to benefit from using ponents。  



           Creating the Translator Class 



           When working with Visual Basic Express; or one of the other Visual Studio products; using the  

           default templates for creating a class library results in the creation of a file named Class1。vb。 It  

           is good that a default file is created for a class library; but the identifier Class1。vb does not imply  

           much。 Therefore; you should go ahead and delete that file from the project (simply renaming  

           the file does not rename the class within it)。 In its place; create the Translator class; as follows: 



                 1。 Right…click the  LanguageTranslator project。 



                 2。 Click Add  New Item。 



                 3。 Select Class。 


…………………………………………………………Page 75……………………………………………………………

                                             CH AP T E R   3   ■    L E AR N IN G   AB O U T   ST R I N G   M A N I PU L A TI O N S  53 



     4

返回目录 上一页 下一页 回到顶部 2 2

你可能喜欢的