3 ms·
Not just invariants, covariants as well. State and zip code always change together. Having had to fix code that passed 5 variables around for an address (which
by hinkley 6y ago
Not just invariants, covariants as well.
State and zip code always change together. Having had to fix code that passed 5 variables around for an address (which needed to go to 6 for “address 2”) I replaced it with an address object.
- lmm 6y agoAn address datastructure is a good thing. I'm not at all convinced that an address object - one with behaviour - is.
- umanwizard 6y agoYou can have an address struct, and functions that manipulate it in controlled ways (like always updating the state when the ZIP changes), in every language, whether OOP or not.
- HeyLaughingBoy 6y agoThat is OOP, regardless of what the language is.
- umanwizard 6y agoIt’s an OOP technique, yes, but functions operating on structures predate OOP and are used in practically every program, so they’re not enough to claim that a program is written in OOP style without the term losing all meaning. For me, true OOP requires some sort of inheritance and/or runtime method dispatch, at least.
- HeyLaughingBoy 6y agoOK, I'll go along with that. The description given doesn't contain a full "implementation" of what OOP is considered to be. Can we at least agree that limiting operations on the structure to the code that controls that structure is following the definition of encapsulation, which is what I should have said anyway?
- deleted 6y ago[deleted]