ADTs and objectsAfter reading William Cook's essay "On Understanding Data Abstraction, Revisited", let me try to condense the difference between abstract data types (ADTs) and objects into a few words. (To avoid ambiguity, I use "instances" to stand for data created by instantiating ADTs)
Ironically, it is usually the former case in mainstream object-oriented languages like Java and C++. In Java you can somehow achieve the latter with interfaces and anonymous classes, but it is awkward. JavaScript's prototype-based system seems to be closer to the essence of the latter, but still not feel natural. But different from Cook's view, I think it is better not to consider binary operations like set union as methods. Union may take two sets with different representations and create a new one, thus it can operate by using the "true methods" of both arguments (possibly iterators and membership). |