ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
µÚÈýµç×ÓÊé ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ44²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡


ActiveCurrencyTrader¡¡will¡¡not¡¡be¡¡covered¡¡in¡¡this¡¡chapter£»¡¡because¡¡polymorphism¡¡is¡¡the¡¡subject¡¡¡¡

of¡¡the¡¡next¡¡chapter¡£¡¡Just¡¡keep¡¡what¡¡you¡¯ve¡¡learned¡¡about¡¡the¡¡MustInherit¡¡and¡¡MustOverride¡¡¡¡

keywords¡¡in¡¡mind¡¡as¡¡you¡¡read¡¡that¡¡chapter£»¡¡which¡¡covers¡¡concepts¡¡such¡¡as¡¡interfaces£»¡¡because¡¡¡¡

you¡¡can¡¡do¡¡the¡¡same¡¡types¡¡of¡¡things¡¡with¡¡them¡£¡¡¡¡



The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡



In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡some¡¡of¡¡the¡¡basics¡¡of¡¡object¡­oriented¡¡programming¡£¡¡Here¡¡are¡¡the¡¡¡¡

key¡¡points¡¡to¡¡remember£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Your¡¡code¡¡will¡¡be¡¡posed¡¡of¡¡structural¡¡£¨or¡¡base¡¡class¡¡functionality£©¡¡and¡¡architectural¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡business¡­related¡¡functionality¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Base¡¡class¡¡functionality¡¡is¡¡focused¡¡on¡¡a¡¡particular¡¡problem¡£¡¡Base¡¡class¡¡functionality¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡requires¡¡specific¡¡knowledge¡¡of¡¡the¡¡field¡£¡¡Think¡¡of¡¡it¡¡as¡¡implementing¡¡a¡¡calculator¡¡where¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡main¡¡concern¡¡is¡¡ensuring¡¡that¡¡the¡¡calculations¡¡are¡¡correct¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Architectural¡¡business¡­related¡¡functionality¡¡is¡¡higher¡­level¡¡functionality¡¡where¡¡general¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡business¡¡knowledge¡¡is¡¡needed¡£¡¡The¡¡idea¡¡is¡¡to¡¡take¡¡the¡¡base¡¡classes¡¡and¡¡use¡¡them¡¡to¡¡solve¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡business¡¡problem¡£¡¡Think¡¡of¡¡it¡¡as¡¡using¡¡a¡¡calculator¡¡and¡¡your¡¡main¡¡concern¡¡is¡¡getting¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡results¡¡of¡¡the¡¡calculations¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Properties¡¡should¡¡be¡¡used¡¡instead¡¡of¡¡exposing¡¡data¡¡members¡¡publicly¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Many¡¡developers¡¡dislike¡¡properties¡¡because¡¡they¡¡promote¡¡bad¡¡programming¡¡practices¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡need¡¡to¡¡get¡¡beyond¡¡those¡¡ments¡¡and¡¡think¡¡in¡¡terms¡¡of¡¡the¡¡credit¡¡card¡¡and¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cashier¡£¡¡Properties¡¡have¡¡their¡¡time¡¡and¡¡place¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Classes¡¡should£»¡¡in¡¡general£»¡¡not¡¡expose¡¡their¡¡state¡£¡¡To¡¡get¡¡around¡¡exposing¡¡state£»¡¡create¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡methods¡¡that¡¡implement¡¡the¡¡general¡¡intent¡¡of¡¡the¡¡purpose¡¡of¡¡the¡¡class¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Inheritance¡¡is¡¡a¡¡fundamental¡¡part¡¡of¡¡Visual¡¡Basic¡¡and¡¡you¡¡will¡¡need¡¡to¡¡know¡¡how¡¡to¡¡use¡¡it¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Overriding¡¡is¡¡when¡¡you¡¡keep¡¡the¡¡interface¡¡the¡¡same¡¡and¡¡change¡¡behavior¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Overloading¡¡is¡¡when¡¡you¡¡derive¡¡a¡¡class¡¡and¡¡define¡¡an¡¡identifier¡¡that¡¡happens¡¡to¡¡be¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡same¡¡as¡¡some¡¡base¡¡class¡¡identifier¡£¡¡Your¡¡overloaded¡¡identifier¡¡may¡¡change¡¡behavior¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡usage¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Conditional¡¡pilation¡¡statements¡¡can¡¡be¡¡effective¡¡when¡¡you¡¡want¡¡to¡¡include¡¡code¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡certain¡¡configurations¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Partial¡¡classes¡¡are¡¡very¡¡useful¡¡when¡¡you¡¡want¡¡to¡¡separate¡¡functionality¡¡that¡¡serves¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡specific¡¡purpose¡£¡¡In¡¡this¡¡chapter¡¯s¡¡example£»¡¡it¡¡meant¡¡having¡¡the¡¡ability¡¡to¡¡add¡¡test¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡without¡¡violating¡¡the¡¡rule¡¡of¡¡exposing¡¡state¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡184¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

162¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡apply¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter£»¡¡you¡¡can¡¡do¡¡the¡¡following¡¡exercises¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡The¡¡code¡¡for¡¡HotelCurrencyTrader¡£ConvertTo£¨£©¡¡and¡¡HotelCurrencyTrader¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConvertFrom£¨£©¡¡contains¡¡a¡¡potentially¡¡big¡¡bug¡£¡¡Identify¡¡the¡¡bug¡¡and¡¡fix¡¡it¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡In¡¡the¡¡examples£»¡¡the¡¡exchange¡¡rate¡¡is¡¡assigned¡¡by¡¡the¡¡caller¡¡of¡¡the¡¡HotelCurrencyTrader¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡ActiveCurrencyTrader¡£¡¡Implement¡¡functionality¡¡such¡¡that¡¡the¡¡exchange¡¡rate¡¡can¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retrieved¡¡dynamically¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡The¡¡currency¡¡ExchangeRate¡¡property¡¡is¡¡a¡¡Double¡£¡¡Implement¡¡ExchangeRate¡¡using¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Decimal¡¡type¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡£¡¡Write¡¡test¡¡code¡¡for¡¡ActiveCurrencyTrader¡¡and¡¡HotelCurrencyTrader¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡185¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡7¡¡



¡ö¡¡¡ö¡¡¡ö¡¡



Learning¡¡About¡¡ponents¡¡¡¡

and¡¡Class¡¡Hierarchies¡¡



The¡¡previous¡¡chapter¡¡covered¡¡the¡¡basics¡¡of¡¡object¡­oriented¡¡programming¡£¡¡You¡¡learned¡¡how¡¡¡¡

one¡¡class¡¡can¡¡subclass¡¡another¡¡class£»¡¡thus¡¡building¡¡a¡¡hierarchy¡£¡¡Using¡¡a¡¡class¡¡hierarchy£»¡¡classes¡¡¡¡

can¡¡share¡¡functionality¡£¡¡

¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¡will¡¡focus¡¡on¡¡the¡¡details¡¡of¡¡class¡¡hierarchies£»¡¡including¡¡how¡¡to¡¡extend¡¡them¡¡so¡¡¡¡

that¡¡derived¡¡classes¡¡can¡¡specialize¡¡shared¡¡functionality¡£¡¡To¡¡demonstrate¡¡these¡¡concepts£»¡¡we¡¡will¡¡¡¡

build¡¡a¡¡tax¡¡application¡£¡¡This¡¡type¡¡of¡¡application¡¡is¡¡a¡¡good¡¡example¡¡of¡¡using¡¡class¡¡hierarchies£»¡¡¡¡

because¡¡the¡¡general¡¡idea¡¡of¡¡paying¡¡taxes¡¡is¡¡identical£»¡¡regardless¡¡of¡¡the¡¡country£»¡¡but¡¡the¡¡details¡¡¡¡

are¡¡different¡£¡¡

¡¡¡¡¡¡¡¡¡¡From¡¡a¡¡technical¡¡perspective£»¡¡we¡¯ll¡¡cover¡¡the¡¡following¡¡topics£º¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Interfaces£»¡¡which¡¡are¡¡the¡¡basis¡¡of¡¡software¡¡ponents¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Details¡¡of¡¡overloading¡¡and¡¡overriding¡¡methods¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡How¡¡and¡¡when¡¡to¡¡use¡¡factories¡¡



¡¡¡¡¡¡¡¡¡¡We¡¯ll¡¡begin¡¡with¡¡some¡¡basic¡¡tax¡¡concepts¡¡that¡¡relate¡¡to¡¡our¡¡sample¡¡application¡£¡¡



Understanding¡¡Some¡¡Basic¡¡Tax¡¡Concepts¡¡



Taxes¡¡and¡¡death¡¡are¡¡two¡¡sure¡¡things¡¡in¡¡life¡£¡¡Regardless¡¡of¡¡where¡¡you¡¡live£»¡¡the¡¡government¡¡has¡¡¡¡

managed¡¡to¡¡create¡¡a¡¡system¡¡where¡¡you¡¡pay¡¡taxes¡¡£¨for¡¡the¡¡good¡¡of¡¡the¡¡people£»¡¡of¡¡course£©¡£¡¡As¡¡a¡¡¡¡

result£»¡¡people¡¡hate¡¡paying¡¡taxes£»¡¡and¡¡many¡¡figure¡¡out¡¡creative¡¡ways¡¡to¡¡not¡¡pay¡¡taxes¡£¡¡Honest¡¡people¡¡¡¡

who¡¡would¡¡normally¡¡not¡¡break¡¡the¡¡law¡¡find¡¡clever¡¡ways¡¡of¡¡bending¡¡the¡¡rules¡¡in¡¡their¡¡favor¡£¡¡In¡¡¡¡

some¡¡countries£»¡¡they¡¡even¡¡expect¡¡that¡¡you¡¡will¡¡cheat£»¡¡and¡¡will¡¡calculate¡¡your¡¡¡°true¡±¡¡tax¡¡figure¡£¡¡

¡¡¡¡¡¡¡¡¡¡Taxes¡¡seem¡¡like¡¡a¡¡plex¡¡topic£»¡¡but¡¡they¡¡are¡¡rather¡¡simple¡£¡¡The¡¡volumes¡¡of¡¡rules¡¡associ

ated¡¡with¡¡taxes¡¡are¡¡what¡¡make¡¡them¡¡plicated¡£¡¡Taxes¡¡boil¡¡down¡¡to¡¡the¡¡fact¡¡that¡¡if¡¡you¡¡buy¡¡or¡¡¡¡

do¡¡X£»¡¡then¡¡you¡¡can¡¡deduct¡¡or¡¡charge¡¡Y¡£¡¡Sometimes£»¡¡the¡¡taxes¡¡make¡¡sense£»¡¡sometimes¡¡they¡¡don¡¯t¡£¡¡¡¡

Overall¡¡though£»¡¡the¡¡tax¡¡rules¡¡are¡¡similar¡¡in¡¡logic£»¡¡and¡¡that¡¡means¡¡a¡¡hierarchy¡¡of¡¡classes¡¡can¡¡¡¡

be¡¡designed¡£¡¡

¡¡¡¡¡¡¡¡¡¡Taxable¡¡ine¡¡is¡¡the¡¡sum¡¡of¡¡monies¡¡that¡¡you¡¡earned¡¡for¡¡which¡¡a¡¡tax¡¡rate¡¡is¡¡applied¡£¡¡The¡¡¡¡

taxable¡¡ine¡¡may¡¡or¡¡may¡¡not¡¡be¡¡equal¡¡to¡¡the¡¡sum¡¡of¡¡money¡¡that¡¡you¡¡earned¡¡during¡¡a¡¡year¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡163¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡186¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

164¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡H¡¡IE¡¡S¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Taxable¡¡ine¡¡can¡¡be¡¡less¡¡due¡¡to¡¡deductions¡¡and¡¡ine¡¡deferment¡£¡¡And¡¡in¡¡some¡¡cases£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡taxable¡¡ine¡¡can¡¡be¡¡more¡¡due¡¡to¡¡deferment¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Deductions¡¡are¡¡items¡¡that¡¡can¡¡be¡¡charged¡¡against¡¡taxable¡¡ine¡£¡¡People¡¡mistakenly¡¡believe¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡deductions¡¡can¡¡be¡¡charged¡¡directly¡¡against¡¡the¡¡tax¡¡payable¡¡amount¡£¡¡Or¡¡they¡¡mistakenly¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡believe¡¡a¡¡tax¡¡deduction¡¡is¡¡always¡¡an¡¡advantage¡£¡¡For¡¡example£»¡¡let¡¯s¡¡say¡¡you¡¡have¡¡1£»000¡¡of¡¡tax¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡deductions¡£¡¡If¡¡your¡¡ine¡¡is¡¡2£»000£»000£»¡¡then¡¡the¡¡deduction¡¡is¡¡not¡¡worth¡¡much£»¡¡since¡¡your¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡taxable¡¡ine¡¡is¡¡still¡¡1£»999£»000¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Partial¡¡taxation¡¡is¡¡when¡¡a¡¡partial¡¡amount¡¡of¡¡earned¡¡monies¡¡is¡¡added¡¡to¡¡the¡¡total¡¡taxable¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ine¡£¡¡Often£»¡¡partial¡¡taxation¡¡is¡¡applied¡¡to¡¡capital¡¡gains¡£¡¡¡¡Capital¡¡gains¡¡refer¡¡to¡¡when¡¡you¡¡have¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bought¡¡something¡¡like¡¡a¡¡property¡¡and¡¡then¡¡sold¡¡it¡¡at¡¡a¡¡higher¡¡price¡¡than¡¡you¡¡paid¡¡for¡¡it¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡difference¡¡between¡¡the¡¡two¡¡prices¡¡is¡¡subject¡¡to¡¡capital¡¡gains¡¡tax¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡variation¡¡of¡¡partial¡¡taxation¡¡is¡¡¡¡ine¡¡splitting£»¡¡so¡¡that¡¡a¡¡lower¡¡tax¡¡rate¡¡is¡¡achieved¡£¡¡Let¡¯s¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡say¡¡that¡¡you¡¡have¡¡a¡¡household¡¡of¡¡two¡¡people¡£¡¡One¡¡of¡¡the¡¡two¡¡earns¡¡the¡¡ine£»¡¡and¡¡the¡¡other¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡stays¡¡at¡¡home¡£¡¡In¡¡such¡¡a¡¡case£»¡¡the¡¡household¡¡would¡¡be¡¡taxed¡¡at¡¡the¡¡same¡¡level¡¡as¡¡a¡¡single¡­person¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡household¡£¡¡Yet¡¡the¡¡two¡­person¡¡household¡¡has¡¡more¡¡expenses¡£¡¡Thus£»¡¡some¡¡countries¡¡allow¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡household¡¡to¡¡declare¡¡a¡¡single¡¡tax£»¡¡where¡¡in¡¡effect£»¡¡a¡¡single¡¡earner¡¡in¡¡a¡¡two¡­person¡¡household¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡taxed¡¡at¡¡half¡¡the¡¡rate¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡calculating¡¡the¡¡total¡¡tax£»¡¡some¡¡countries¡¡linearly¡¡increase¡¡the¡¡taxation¡¡rate¡£¡¡Typically£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡linear¡¡tax¡¡rate¡¡is¡¡less¡¡for¡¡lower¡¡ines¡¡and¡¡more¡¡for¡¡higher¡¡ines¡£¡¡Another¡¡approach¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡divide¡¡ine¡¡in¡¡chunks¡¡with¡¡different¡¡tax¡¡rates¡¡for¡¡each¡£¡¡This¡¡means¡¡that¡¡those¡¡monies¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡earned¡¡up¡¡to¡¡a¡¡certain¡¡amount¡¡are¡¡taxed¡¡at¡¡a¡¡certain¡¡rate¡£¡¡Monies¡¡above¡¡that¡¡amount¡¡and¡¡below¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡another¡¡higher¡¡amount¡¡are¡¡taxed¡¡at¡¡a¡¡higher¡¡rate¡£¡¡This¡¡chunking¡¡of¡¡the¡¡amounts¡¡and¡¡rates¡¡keeps¡¡on¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡being¡¡calculated¡¡until¡¡a¡¡highest¡¡tax¡¡rate¡¡is¡¡reached£»¡¡where¡¡any¡¡amounts¡¡over¡¡that¡¡upper¡¡limit¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡taxed¡¡at¡¡the¡¡highest¡¡rate¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Organizing¡¡the¡¡Tax¡¡Application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡a¡¡general¡¡rule£»¡¡in¡¡each¡¡country£»¡¡you¡¡must¡¡pay¡¡an¡¡ine¡¡tax£»¡¡which¡¡is¡¡calculated¡¡against¡¡your¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡total¡¡ine¡£¡¡From¡¡your¡¡ine£»¡¡you¡¡can¡¡deduct¡¡certain¡¡expenses£»¡¡thus¡¡lowering¡¡your¡¡taxable¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ine¡£¡¡The¡¡aspects¡¡that¡¡differ¡¡from¡¡country¡¡to¡¡country¡¡are¡¡what¡¡you¡¡can¡¡deduct¡¡and¡¡the¡¡indi

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vidual¡¡tax¡¡rate¡£¡¡These¡¡will¡¡be¡¡addressed¡¡by¡¡the¡¡tax¡¡application¡¡we¡¡will¡¡build¡¡in¡¡this¡¡chapter¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡tax¡¡application£»¡¡the¡¡following¡¡features¡¡will¡¡be¡¡implemented£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Define¡¡a¡¡taxable¡¡ine¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Define¡¡a¡¡series¡¡of¡¡deductions¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Implement¡¡a¡¡tax¡­calculation¡¡engine¡¡that¡¡has¡¡the¡¡ability¡¡to¡¡account¡¡for¡¡families¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡single¡¡earners¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡in¡¡previous¡¡examples£»¡¡the¡¡project¡¡structure¡¡of¡¡the¡¡taxation¡¡application¡¡will¡¡consist¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡two¡¡projects£º¡¡a¡¡console¡¡testing¡¡application¡¡and¡¡a¡¡library¡¡ponent¡¡that¡¡contains¡¡the¡¡function

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ality¡£¡¡The¡¡library¡¡ponent¡¡will¡¡be¡¡in¡¡a¡¡project¡¡called¡¡LibTax£»¡¡and¡¡the¡¡testing¡¡application¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡be¡¡in¡¡a¡¡project¡¡called¡¡TestTax¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Before¡¡we¡¡start¡¡coding£»¡¡however£»¡¡you¡¡need¡¡to¡¡understand¡¡the¡¡concepts¡¡of¡¡interfaces¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ponents¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡187¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡HI¡¡E¡¡S¡¡165¡¡



Programming¡¡Using¡¡Ideas¡¡



At¡¡this¡¡moment£»¡¡we¡¡don¡¯t¡¡have¡¡a¡¡clue¡¡where¡¡to¡¡start¡¡building¡¡the¡¡tax¡¡application£»¡¡because¡¡the¡¡¡¡

problem¡¡is¡¡in¡¡the¡¡details¡¡of¡¡the¡¡implementation¡£¡¡Unlike¡¡previous¡¡examples£»¡¡where¡¡it¡¡was¡¡¡¡

possible¡¡to¡¡gauge¡¡what¡¡tests¡¡were¡¡needed£»¡¡in¡¡this¡¡example£»¡¡we¡¡simply¡¡do¡¡not¡¡know¡£¡¡We¡¡could¡¡¡¡

start¡¡by¡¡implementing¡¡the¡¡general¡¡tax¡¡rules¡¡and¡¡then¡¡applying¡¡them¡¡to¡¡a¡¡specific¡¡system¡£¡¡But¡¡¡¡

what¡¡if¡¡our¡¡general¡¡tax¡¡rule¡¡implementations¡¡didn¡¯t¡¡actually¡¡work¡¡out£¿¡¡We¡¡would¡¡have¡¡wasted¡¡¡¡

time¡¡writing¡¡code¡¡that¡¡we¡¡would¡¡end¡¡up¡¡throwing¡¡out¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡the¡¡following¡¡situation£º¡¡you¡¡write¡¡a¡¡series¡¡of¡¡base¡¡classes¡¡that¡¡represent¡¡a¡¡generic¡¡¡¡

taxation¡¡kernel¡¡based¡¡on¡¡the¡¡information¡¡in¡¡the¡¡¡°Understanding¡¡Some¡¡Basic¡¡Tax¡¡Concepts¡±¡¡¡¡

section¡£¡¡The¡¡base¡¡classes¡¡need¡¡a¡¡task£»¡¡and¡¡thus¡¡wait¡¡for¡¡a¡¡client¡£¡¡A¡¡little¡¡while¡¡later£»¡¡an¡¡individual¡¡¡¡

from¡¡the¡¡United¡¡Kingdom¡¡desires¡¡a¡¡tax¡¡program¡¡based¡¡on¡¡the¡¡base¡¡classes¡£¡¡The¡¡developers£»¡¡¡¡

eager¡¡to¡¡show¡¡off¡¡the¡¡usefulness¡¡of¡¡their¡¡base¡¡classes£»¡¡implement¡¡the¡¡tax¡¡program¡£¡¡The¡¡idea¡¡is¡¡¡¡

that¡¡you¡¡save¡¡time¡¡by¡¡using¡¡the¡¡base¡¡classes¡¡to¡¡implement¡¡something¡¡specific¡£¡¡Without¡¡the¡¡base¡¡¡¡

cla
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨0£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡