總網頁瀏覽量

2016年3月22日 星期二

[Java] SCJP 例題 020/例題 023/例題 024

例題 020 

A team of programmers is reviewing a proposed API for a new utility class.
   一組程式設計師正在檢視一個新工具類別的程式設計介面(API)

After some discussion經過一些討論之後,
 
they realize that they can reduce the number of methods in the API without losing any functionality.
   他們了解到,在沒有喪失任何功能情況下,可以降低這組API的方法數量。


If they implement the new design, which two OO principles will they be promoting?
   如果他們實作這個設計(想法),他們必須遵循那二個OO的原則?[1]

   A. Looser coupling
   B. Tighter coupling
   C. Lower cohesion
   D. Higher cohesion  
   E. Weaker encapsulation
   F. Stronger encapsulation
 
 
[1] http://192.192.246.169/~wells/wiki/index.php/SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_020 

這題非常非常陌生, 感覺沒看過這種敘述,
雖然以前老師有提過, 但是只要一個禮拜不看就忘了這回事.
 
這題自己寫的時候還是記得把中文蓋著吧, 感覺考是應該沒有. 

依照網站上的解析
 
 Coupling:模組間的耦合度,愈低愈好,亦即模組獨立性要高
 Cohesion:模組的內聚力,表示模組內的成員都是為模組單一功能的設計而共同存在

 一般來說,設計系統,分割功能模組必須模組間不能互相牽連,以介面做為模組間溝通的工具,當一個模組修改時,另一個模組不致於也要跟著修改。
 而一個功能模組僅實現單一功能,不會一個模組要同時實現多個功能使得模組內變得超複雜。 

好像把目標放在Coupling和Cohesion兩個的解釋上.
Looser coupling 鬆散耦合 
Lower cohesion  低凝聚力
 
 
 
- - - - - - - - - - - 
例題 023 
 
A company has a business application that provides its users with many different reports: receivables reports, 
payables reports, revenue projects, and so on.
  某家公司有一個商用程式,提供它的使用者許多報表製作,像是…

The company has just purchased some new, state-of-the-art,wireless printers, 
and a programmer has been assigned the task of enhancing all of the reports to use 
not only the company‘s old  printers, but the new wireless printers as well. 
  這家公司剛好採購了一些新的、完美的無線印表機,一個程式設計師被指定一個工作-加強報表功能,
  使得原本的報表功能不只可以使用舊的印表機,也能使用這些新式的印表機!

When the programmer starts looking into the application, 
the programmer discovers that because of the design of the application, 
it is necessary to make changes to each report to support the new printers. 


Which two design concepts most likely explain the situation? (Choose two.)

   A. Inheritance
   B. Low cohesion
   C. Tight coupling
   D. High cohesion
   E. Loose coupling
   F. Object immutablility 


由上面兩題看, 要把功能緊緊綁在一起, 讓新舊並行,
就需要Low cohesion和Tight coupling,  (023)
而開發新的功能要與舊的有差異, 不要讓重覆工能太多,
就需要Looser coupling 和 Lower cohesion . (020)
 
好項需要去看一下影片, 有看到有人說要老師提供. ㄏㄏ 
 
- - - - - - - - - - 
 例題 024 
 
A company that makes Computer Assisted Design(CAD) software has, 
within its application some utility classes that are used to perform 3D rendering tasks. 
  有一些工具類別被使用來進行3D著色工作

The company's chief scientist has just improved the performance of one of 
the utility classes' key rendering  algorithms, and has assigned a programmer to replace the old algorithm 
with the new algorithm.

When the programmer begins researching the utility classes, 
she is happy to discover that the algorithm to be replaced exists in only one class.
The programmer reviews that class‘s API,
and replaces the old algorithm with the new algorithm, 
being careful that her changes adhere strictly to the class’s API.

Once testing has begun, 
the programmer discovers that other classes that use the class she changed are no longer working properly. 
  (她發現到…她做了一些改變之後,一些使用到她改變的類別的其他類別再也不能正常地運作…)
   

What design flaw is most likely the cause of there new bugs?
  A. Inheritance
  B. Tight coupling
  C. Low cohesion
  D. High cohesion
  E. Loose coupling
  F. Object immutablility
 
感覺上是因為耦合度太高導致功能重疊就修改到了 

沒有留言:

張貼留言