Pattern matching. What is it used for?

Started by
11 comments, last by SamLowry 12 years, 2 months ago

[quote name='SamLowry' timestamp='1327500122' post='4906099']
Given code which you may not alter, OO does allow you to define extra subclasses (for which you need to implement the necessary abstract methods, etc.), but you cannot add new methods to an existing class hierarchy "from the outside".


There's nothing about OO in and of itself that prevents this. Though the languages that served to popularise OO tend not to support features such as structural typing or pattern matching.
[/quote]
Depends on your definition of OO. If you take it "whatever C++/java/C#/Eiffel implement", then there's no simple way of adding methods. But of course, in the "true" definition of OO, I'm sure no one includes "and it absolutely must be impossible to do this". Do you know of a language which supports adding methods, and performs some sort of static verification?
Advertisement
C#'s extension methods serve this purpose though they're not strictly 'added' depending on your definition/requirements.

C#'s extension methods serve this purpose though they're not strictly 'added' depending on your definition/requirements.

C# extension methods don't really count in my eyes: they're nothing more than syntactic sugar for static methods in a separate class. There's no dynamic dispatch going on. (But admittedly, they're still quite useful.)

Someone told me some next version of java will have some sort of extension mechanism, but based on the information I got it would still require a lot of instanceofs to operate on existing hierarchies.

This topic is closed to new replies.

Advertisement