what are their similarities and differences?
How is a set method different from an initialize method?
You must be signed in to leave a comment
26 April 2019, 14:33
In 'best practice' initialize is used to set all the necessary class properties to values that make the object valid. Valid being that the code won't throw any exceptions like 'division by zero' or 'null pointer' (or any other), while the set<propertyName> methods are used to set the value of only one property. I say 'best practice' because these names are completely arbitrary. You can name methods whatever you want and have them do whatever you want. There are only a few keywords that are reserved and not able to be used as method names. You could create a method that supposedly divides 9 by 3, but returns 2 + 2 :or one that "gets" 4, but returns 6: Do these make sense? probably not. Is it legitimate code? Yes!!
26 April 2019, 15:25
Thanks for clearing it up.