79482341

Date: 2025-03-03 23:26:06
Score: 0.5
Natty:
Report link

"Function do_something_1() As String" is better OOP, as it is better encapsulation and abstraction, two pillars of OOP. However it depends on the actual real life usecase as always. From the given usecase the first option is clearly better OOP.

TLDR: You don't want the second option in this case, as it means you are telling the function the name and surname from where ever you are calling it from. Not only is this redundant, but you're also bypassing whatever names are already in the class.

In a bit more detail: If you needed to call the second function, first you'd have to get the name and surname, and only then can you call the second function externally; which is messy and poor abstraction. While from within the function you are just redundantly passing variables the function already has, also messy, and adds more parameters to your function. (Some functions already have a bunch of parameters, so the last thing you want is even more). Secondly if you make a mistake and passed your function the wrong name (regardless of if called externally or from within the class), it would use that instead of the classes variable.

Only if you wanted to call the function with a different name and surname from the ones inside the class, would you have a function like your second option.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Michael Serretta