3 ms·
Using classes doesn't necessitate using inheritance and polymorphism. Whenever I'm programming in a non-OOP language, I still gravitate towards class-like code.
by skocznymroczny 7y ago
Using classes doesn't necessitate using inheritance and polymorphism. Whenever I'm programming in a non-OOP language, I still gravitate towards class-like code. From my perspective, there isn't much different between:
doStuff(&fooStruct, ...) vs. fooClass.doStuff(...)
- djsumdog 7y agoThe core difference is in testing. With the later, you need to get your class into the right state to preform the test. You might even need a mock or two. With the non-OOP approach, you set the entire state of the function and see the results.
- Ididntdothis 7y agoIs that even true? In the end it’s all the same code. You can write classes that need a lot of context but the same can happen with functions.
- jayd16 7y agoIf the method needs just as much state in a struct as you would on a class then its equivalent.
- Double_a_92 7y ago> you set the entire state And how would you easily create that state?
- Ididntdothis 7y agoYou create a mock :)
- aidenn0 7y agoYou are wrong. You need to create just as much state in fooStruct as fooClass in the example GP gives.
- brobinson 7y agoYou might find this interesting: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax