← Back to context

Comment by mrkeen

4 days ago

> Another criticism comes from functional programmers, who argue that you don’t need to maintain invariants and thus don’t need much information hiding if data is immutable.

Yep

> Information hiding also encourages people to create small, self-contained objects that “know how to handle themselves,” which leads directly into the topic of encapsulation.

This is where it all goes wrong. No module is an island. There's always relationships between different objects/modules/actors in your system.

Who delivers a letter: Postman or Letter? Who changes a light globe, Handyman or LightGlobe?

Things rarely handle themselves - and if they do, it's probably just a pure function call - so why use Objects?

If you start bending over backwards to implement Letter.deliver(Postman p) (and then make it "general" by changing it to IPostman) you'll never stand up straight again. What if I have a List<Letter>, where does the deliver() code go now?"

If you instead write Deliver(Postman p, Letter l), the opportunities to rewrite/refactor/batch just present themselves.