top | item 40029320

(no title)

ejflick | 1 year ago

> "yeah I have a User, but I don't know if it's a valid User".

This, imo, is one of the big reasons people so easily dismiss OOP. They put whatever data _they think they probably need_ in an object using setters/builders/what have you. This leads to abstractions of data that don't accurately reflect state. They will then let an external entity (service or whatever pattern) manipulate this data. At this point people might as well use something analogous to a C struct where anything can be done to the values. Objects are not managing their own invariants. When you rip this responsibility from an object, then nothing becomes responsible for the validity of an object. Due to this, people wonder why they get bugs and have trouble growing their software.

This also leads to things like "isValid". People don't understand that an object should be constructed with only valid data. The best example I've found of protecting variants and construction of valid objects to be this strategy in F#:

https://fsharpforfunandprofit.com/series/designing-with-type...

I'm yet to find a good way to do this in a language such as Java unfortunately.

discuss

order

CharlieDigital|1 year ago

In psychology, there is an idea of "locus of control".

I think OOP done well and applied in suitable scenarios results in entities that have internal locus of control; it's mutations of state are internally managed.

OOP done poorly has external locus of control where some external "service" or "util" or "helper" manages the mutation of state.