友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

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

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






               o  Code that implements has the responsibility of throwing exceptions。 Code that imple

                  ments does not try to fix or swallow the exception。 This means code that implements will  

                  implement a  Finally block to reset state; but usually not a Catch block。 



               o  Code that organizes has the responsibility of being aware that exceptions might occur。  

                  This means code that organizes will implement Catch blocks to catch exceptions and  

                  process them。 Usually; this code will not have a  Finally implementation; but it may  

                  filter exceptions。 



               o  Exceptions can be filtered to determine which exceptions will be captured and which  

                  cannot be captured。 



               o  You can help make your code exception…safe by implementing sandboxing  

                  functionality。 



               o  Implement default state so that your code is easier to read and maintain。 



           Some Things for You to Do 



           To apply what you’ve learned in this chapter; here’s what you can do; summed up in a single step: 



                1。  Rewrite all of the code examples in Chapter 4 to be exception…safe。 


…………………………………………………………Page 157……………………………………………………………

C  H  A  P  T  E  R     6 



■ ■ ■ 



Learning the Basics of Object

Oriented Programming 



At this point; you should be fortable with writing basic Visual Basic code; but your coding  

style would solve problems directly without considering reusability or other more advanced  

concepts。 You could code yourself out of a wet paper bag; but once you were out of the bag; you  

would have no idea what to do next。 (In case you’re interested; the phrase; “You couldn’t do 'fill  

in topic' out of a wet paper bag” implies that your skills in a certain area are so weak that a wet  

paper bag is more overpowering。 The reference to wet paper bag es from the fact that wet  

paper bags have no holding power and will tear at the slightest nudging。) 

     This chapter focuses on reusing base functionality; where two classes share methods and  

properties in mon to solve a particular problem。 To demonstrate the concepts; we will create  

a simple currency exchange application。 This application will use object…oriented programming;  

a powerful set of techniques mon in modern programming languages such as Visual Basic。 

     In this chapter; you’ll learn about the following topics: 



     Object…oriented programming: Object…oriented; often abbreviated as OO; refers to a way of  

     building applications using instantiated types。 First; you define the type and its behavior。  

     Then; when instantiated; the type has a state。 When you are developing; you don’t know  

     the state of the object; so you can only guess at it。 



     Data member scopes: Types have methods; and methods can be called by other types。 But  

     do you want to let all types call all of a type’s methods? Think of it as follows。 When you are  

     at a party; do you want to allow everyone to grab into your pockets? No; you want to control  

     access to your pockets; just as you want to control access to your type’s methods。 



     Properties: There are methods; and there are properties。 Methods are supposed to do things  

     to a type。 Properties are external state representations of a type。 



     Base classes: The term base class denotes mon functionality。 We use the word  base;  

     because in object…oriented programming; hierarchy is defined from the base upwards。 We  

     use the word class; because class is the basic type that contains functionality。 



     Let’s begin with some background on how currency exchange works; which applies to the  

currency converter application we’ll develop in this chapter to demonstrate object…oriented  

programming concepts。 



                                                                                                           135 


…………………………………………………………Page 158……………………………………………………………

136       CH AP T E R   6   ■    L E A R N IN G   T HE   B AS IC S  O F   OB J E CT OR I E N T E D   P R O G R AM M IN G 



           Understanding Currency Spreads 



           This chapter’s sample application deals with exchanging different currencies。 Did you know  

           that when you exchange one currency for another; you never need to pay a processing fee?  

          Whether you are exchanging currencies at some airport or on an exchange; you should not be  

           charged any processing fees。 It makes you wonder how people earn money by accepting one  

           currency and then giving out another currency。 The answer lies in how currency exchange works。 

                When dealing with currencies; you are always dealing with currency pairs。 This is different  

           from something like buying a stock; when you are dealing with only that stock。 A currency by  

           itself is actually quite useless。 Suppose you have a 100 in your hand。 What will it be worth one  

           year from now? The answer is simple: 100。 Yes; you can argue that the 100 will not buy as  

           much next year; but that would be plicating the issue with concerns not related to this  

           discussion。 The fact is that if you have 100 dollars; 100 yen; 100 euros; and so on into infinite  

           time; you will always have 100 currency units。  

                Currency exchange involves paring one currency to another currency。 The value of a  

           currency is what one person would give in parison to another currency。 

                Foreign exchange (forex) market traders make their money by dealing in spreads。 Spreads  

           are tricky because; as the exchange rate moves up or down; so does the spread。 For example;  

           hotels always give you horrible rates; and you may wonder why they are ripping you off。 But  

         
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!