5 ms·
I'd say that Encapsulation was the primary property of OOP - taking a bunch of variables and functions and wrapping them up together. Polymorphism is probably
by AndrewDucker 17y ago
I'd say that Encapsulation was the primary property of OOP - taking a bunch of variables and functions and wrapping them up together.
Polymorphism is probably second, with interface implementation being more useful than inheritance a lot of the time.
Polymorphism would come third.
- kls 17y agoThe problem is the traditional languages that one would reference as symbols of OOP, have all embraced an Anemic Domain Model anti-pattern for their standard development best practices, this kind of negates some of the higher level advantages of OOP.
- Jach 17y agoI figure the whole concept of message passing is the heart of OOP, with encapsulation being a tidy way to go about it and inheritance and polymorphism being nice, powerful add-ons.
- AndrewDucker 17y agoWithout encapsulation, what do you pass a message _to_? (Honestly curious)
- DougWebb 17y agoEncapsulation generally refers to private data, but you could define classes that are just collections of methods, and you can define interfaces that are just collections of method signatures. An object which claims to support an interface can accept any of the messages defined by that interface, and another object can pass messages based on that. A javascript example: in javascript, functions are objects, and can have methods. function MyFunction(...) { ... }; MyFunction.method1 = function(...) {...}; MyFunction.method2 = function(...) {...}; MyFunction.method3 = function(...) {...}; Now, you can pass the messages 'method1', 'method2', or 'method3' to MyFunction. Message passing without encapsulation (as it's usually thought of.) Of course, MyFunction has some default properties too, and you can define more: MyFunction.data1 = ...; MyFunction.data2 = ...; That gives you traditional encapsulation, especially if you use somewhat more complex syntax to make the data private instead of public.
- scott_s 17y agoQuoth Alan Kay, taken from the article: OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them. That's, in order, message passing, encapsulation and polymorphism. I think his primary goal was message passing and late binding; encapsulation is how to implement that. That doesn't mean encapsulation is more important.