New answers tagged

0

There are no real differences between methods, functions and procedures, they're all the same beast: a subroutine, a section of a program, often named doing a specific task. A method is just a function by another name. Even java has functions: in "a + b" the "+" operator is a function. Even if it goes by another name. Imagine you would make a new ...


0

In my opinion in Java there are no functions. All we have are: Object's methods Class methods (the static ones) Functions, as standalone functions, do not exist in Java. I would like to support my brief and categorical answer, citing Java's Official Web Page Software objects are conceptually similar to real-world objects: they too consist of state ...


0

Most likely the method belongs in the Season and not the Player class, but it could go either way. The most important thing is to prevent circular dependencies. If Season calls any methods in Player, then Player should not call any methods in Season. And vice versa. You get to pick which one depends on the other. If you already have methods of Season that ...


0

The rule to learn and apply is:- "An action on a real-world object, becomes a method of that object in object-oriented code" An object in oriented-code knows itself how to do things. So, a player knows its scores, and has methods to reflect that. By contrast in procedural code, a procedure asks something else (can be an object, another procedure, ...


0

The __get magic method is completely fine, just make sure to couple it either with the @property (if you want a magic __set as well) or @property-read phpDoc annotation so consumers of your class know what they can expect from the public API of your class. PHP's combination of __get and __set methods and the @property annotation is a poor-man's version of ...



Top 50 recent answers are included