5 ms·
> Why OO? Classes exist to decouple behaviors from data. This seems like the opposite of how it generally works. Classes tie behaviors to data. This is what pe
by chc 13y ago
> Why OO? Classes exist to decouple behaviors from data.
This seems like the opposite of how it generally works. Classes tie behaviors to data. This is what people generally seem to mean when they talk about encapsulation in OO — the behavior and the data are bound together very well.
- cgag 13y agoYeah, I thought coupling data and behavior was more or less the definition of an object.
- Fargren 13y agoAs long as an object's behaviour remains the same, the data can change without any problem. That's one of the big selling points of OO.
- platz 13y agoSo, then is there some vocabulary that is lacking to describe the difference between these two ideas, but seem to use the same words?
- gnaritas 13y agoThey work together, by encapsulating the data internally, one is free to change its representation. It keeps the coupling to that data local, the objects methods.
- sklivvz1971 13y agoIf you have a datetime object you can stop thinking about the fact that it's internally implemented with e.g. ticks since the epoch. In fact, you don't care anymore what data it depends on, because you only depend on behaviors.
- weavejester 13y agoThat's more polymorphism than encapsulation.
- sklivvz1971 13y agoI was thinking more in terms of different versions of the same library, which is clearly one of the reasons why we have encapsulation :-)
- weavejester 13y agoI can see encapsulation being useful in that case, though I'm of the opinion the use-cases for encapsulation don't outweigh the disadvantages it brings.
- deleted 13y ago[deleted]
- chongli 13y agoThat's called data abstraction. You don't need classes or mutable objects to implement data abstraction.