method return type | Sololearn: Learn to code for FREE!
+ 2

method return type

when we should use method has a parameter, method not has a parameter and method return value???? From question how i can define it?????

10th Oct 2018, 6:00 AM
Sanaa Hareb
Sanaa Hareb - avatar
1 Odpowiedź
+ 5
Having data used from everywhere makes it hard to track down where it gets modified incorrectly. Therefore, OOP was conceived. The main concept is to hide data via functions or methods. If there is only one method used to get the data, there is only one place to verify it is valid. The method return type would be the same as the underlying data being returned. Since methods shouldn't be accessing data that doesn't belong to them, the caller would pass the required data as arguments during the call. This is mapped to the corresponding parameter of the method making the data a local copy. Assuming the data isn't a class, modifying the parameter would have no effect on the original. Since all class modifications should be via methods, all modifications should be as designed for that class.
10th Oct 2018, 6:34 AM
John Wells
John Wells - avatar