Home Discussion Discuss: What is the flaw with the Stack class?

  • Stack IsA Vector?ilhyung cho June 13, 2014 at 1:57 AM

    A stack is not a vector. It should not be. It violates the fundamental isA rule in class design in object orientation. I can hardly believe that Java engineers did not know that. That being said, I think it can be an exception for some utility classes like Stack. If you look at Java's collection hierarchy, it starts from the interface Collection, and then interface Set, List, and Queue. If Stack is to fit in the class/interface hierarchy and to meet the isA rule, there is hardly any place that it can fit. I guess Stack being a subclass of Vector is a compromise. Sometimes, we need to bend a rule. There is no rule without an exception.

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Related Articles