Collection framework design errors: Stack!

  Abstract: Collection framework design errors: Stack! 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="270" height="86" align="center" valign="top"> </ td> <td width="414" valign="top"> 

  Stack Design Collection in Java is a major mistake, this class is absolutely rubbish, Stack design of this class was definitely a brain fever.    As we all know, Stack realized in the data structure of the function stack, which is the first to be backward, look at the statement Stack it: 

  Public class Stack extends Vector 

  Vector is not what has been a good thing, here also inherit it?    Listed here in the Stack, the realization of not consider it, because if you use this stuff, and I had no way can be said. 
  Public Object push (Object item) 
  Public synchronized Object pop () 
  Public synchronized Object peek () 
  Public synchronized int search (Object o) 
  Public boolean empty () 

  You may feel that these methods will be nothing, but when it is a continuation of Vector, which means that it has no value, but the realization of this type is relatively simple, interested can look at the source.    We know that Vector List interface is realized, Stack Vector natural inheritance has also realized the List interface.    In fact Stack List is not even Collection not.    Designers is not only to save this code designed ah ah, but we should be designed to minimize the interface.    If this can be the case, simply Collection with a framework to achieve good class! 

  Stack above should be only a few, there should not be other ways, and the existing design can be used to Stack as Vector. 
  List stack = new Stack (); 

  Have you ever seen such a code will not feel uncomfortable?    I strongly recommend not to use Stack! 

  </ Td> </ tr> <tr> <td height="20" colspan="2"> 

  </ Td> </ tr> </ table> </ td> </ tr> <tr> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , , ,

Releated Java Articles

Comments

Leave a Reply