3 ms·
Not to mention the fact that they completely ignored class methods. No, static methods do not count.
by malbs 14y ago
Not to mention the fact that they completely ignored class methods.
No, static methods do not count.
- i386 14y agoOut of curiosity, why do statics not count for class methods?
- malbs 14y agoclass methods are virtual
- hboon 14y agoThey are closer to global functions that are attached to classes and don't support inheritance the same way as instance methods. e.g. if a subclass implements a static function with the same signature as its parent, and you call it with the parent class, it invokes the parent class version instead of the subclass version. Class-side methods in Smalltalk are inherited, working with classes (as an object) is analogous to how instance-side methods work with instances (also objects). So e.g implementing and using factory methods are simpler in Smalltalk and similar languages. Edit: grammer and typos.
- jcampbell1 14y agoThe only difference I know of is that you can override inherited class methods, but not in Java. Is that really an important feature that you use? I suppose you could use it to do "factory" stuff, without an actual factory class.
- malbs 14y agoexactly! Imagine my surprise when I disovered Delphi has class methods too, but they were not copied to C#. I guess most of the time they're not particularly useful, but when you do need to create some factory code, having pure virtual class methods (template methods), is really useful. Downside w/ Delphi is the metaclasses do not implicitly exist - you have to manually define it, eg TMyObjectClass = class of TMyObject; They should just be implicity, when you define a class, the metaclass is defined too. I guess when they first designed it memory constraints were still a consideration