4 ms·
AbstractFactoryFactory seems like an inevitability of object orientation. I have to wonder why we don't see it as often in other OOP languages. I'm not versed i
by MatthewPhillips 14y ago
AbstractFactoryFactory seems like an inevitability of object orientation. I have to wonder why we don't see it as often in other OOP languages. I'm not versed in Ruby or Python so I can't comment on those. In JavaScript there isn't the concise class or extends/implements keywords and people tend to hide how a library is implemented behind a closure that prevents you from extending it.
So I wonder if Java just gets the blame because it is the most pure object oriented language. It doesn't put up walls preventing you from doing what OOP really wants you to do. C# is the same way, by the way, you see IThisOnlyExistsToBeGeneric<T> all of the time; AbstractControllerBase is a real class in C# MVC if I remember correctly.
What walls does Ruby and Python have that prevents this? Because I see no reason why people aren't doing it.
- lars 14y agoThere reason you don't see interfaces or abstract classes in Ruby or Python is because they are dynamically typed. Interfaces and abstract classes are byproducts that are required for Java and C#'s type systems to work. What use would you have for them in Ruby?
- zimbatm 14y agoI still reason in terms on interfaces when passing arguments to a function though (eg: argument X needs to behave like a string). It will later be verified in runtime and when running the tests but it's how I reason when structuring the code.
- viraptor 14y agoActually Zope.interfaces for Python are more popular than I expected. Not sure how I feel about it really. They're both annoying and useful.
- willismichael 14y agoCould you clarify what you mean by "most pure object oriented language"? This seems disingenuous to me, since if you ask the users of a dozen different OO languages what "OO" means, you'll get a dozen different answers. http://www.paulgraham.com/reesoo.html http://www.paulgraham.com/reesoo.html
- ek 14y agoMy best guess would be object-oriented in the Smalltalk/Self/etc. sense as other posters have alluded to. It's a hard distinction to understand/qualify. Jim Copelien gave a keynote at SPLASH this year about this distinction that left many people confused, but the big takeaway seemed to be that people limit the expressiveness of real object-orientation by instead focusing on classes and prototypes and whatnot. What he sees as a potential embodiment of real object-orientation (together with Trygve Reenskaug, inventor of MVC) is a paradigm they are calling DCI (Data, context, integeration).http://en.wikipedia.org/wiki/Data,_Context,_and_Interaction http://en.wikipedia.org/wiki/Data,_Context,_and_Interaction
- lars 14y agoNeither Smalltalk nor Self had interfaces, and never needed them. Let's be clear, interfaces give nothing to a dynamic language. If you bring them into a dynamic language, you are essentially inventing code contracts - which can be useful, but they serve a fundamentally different purpose than a Java interface.
- viraptor 14y agoMy guess would be that most factories in Java are just very thin wrapper that do "if this return new A(); if that return new B();". This just doesn't need to be done explicitly in a dynamic language. Instead of creating a factory you could pass the class itself as an argument. In Python class is also a factory of its own instances, so the whole reason for wrapping it into another object disappears. And if you do want some logic in the factory, you can just create one without changing the interface. Callee doesn't care when calling x() whether x is a type, factory, or something else. As long as it returns an instance, everyone is happy. (that makes factories disappear from the signatures)
- icebraining 14y agoI disagree; there's nothing pure about Java as an OOP language. In an OOP language, as defined by Alan Kay - who coined the term and popularized the concept - the key characteristics are that everything is an object and objects send messages to each other, while hiding their own state. Classes are not fundamental, but if they exist, they must be objects themselves. As for JavaScript, the fact that people tend to use sealed closures is not a defining characteristic, anymore than having final classes. JavaScript has Prototypes, and they can be extended just fine. "[java]’s a pop culture. A commercial hit record for teenagers doesn’t have to have any particular musical merits."
- yxhuvud 14y agoYou want an AbstractFactoryFactory in Ruby? Heres the only one I've ever used or needed: Class What does your pattern add to that?