Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Performance wise they will be identical. In both cases you are passing a single reference (which has the same performance cost) and in both cases you're getting the <code>PersonType</code> object out of one of the fields.</p> <p>The only difference here is in terms of code readability/maintainability, etc. In general, it's best for methods to only accept what information they need. If you only need a <code>PersonType</code> then only accept a <code>PersonType</code>. It allows that method to be used more flexibly. (What if something other than a <code>Person</code> has a <code>PersonType</code>?) If you think you'll actually need more than just the person type than accepting a <code>Person</code> may be appropriate.</p> <p>Also note that even if there is a difference here, it would most certainly be tiny. You shouldn't think about every little think in terms of how expensive it is to run. Computers are fast these days. Even poor algorithms tend to take little time to run in practice (from the point of view of a person). If you get to the point where your program is taking longer to run than it needs to, then it's time to start looking for places to improve. You should focus on those areas of the code (identified with a profiler) as being a significant percentage of the processor time. Network communication (including database calls), and other IO tend to be good targets for optimizations.</p> <p>Also note that it's generally considered bad practice to have public fields. At the very least, you should probably have public properties instead.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload