classBankAccount{privateint balance =100;publicintgetBalance(){return balance;}publicvoidwithdraw(int amount){balance = balance - amount;}}publicclassRyanAndMonicaJobimplementsRunnable{private BankAccount account =newBankAccount();publicstaticvoid main (String[] args){RyanAndMonicaJob theJob =newRyanAndMonicaJob();Thread one =newThread(theJob);Thread two =newThread(theJob);one.setName("Ryan");two.setName("Monica");one.start();two.start();}publicvoidrun(){for(int x =0; x <10; x++){makeWithdrawal(10);if(account.getBalance()<0){System.out.println("Overdrawn!");}}}privatevoidmakeWithdrawal(int amount){String currentThread = Thread.currentThread().getName();if(account.getBalance()>= amount){System.out.println(currentThread +"is about to withdraw");try{System.out.println(currentThread +" is going to sleep");Thread.sleep(500);}catch(InterruptedException ex){ex.printStackTrace();}System.out.println(currentThread +" woke up.");account.withdraw(amount);System.out.println(currentThread +" completes the withdrawl");}else{System.out.println("Sorry, not enough for "+ currentThread);}}}
```
第五章第一節 可復用性的度量、形態和外部觀察 面向復用編程(programming for reuse):開發出可復用的軟件 基于復用編程(programming with reuse):利用已有的可復用軟件搭建應用系統 代碼復用的類型: 白盒復用:源代碼可見&#x…