Getter vs method directly using input parameter

I came across this code (simplified, of course) in the project to which I was assigned.

Method Option 1

public myType getSomething(final int pTeamId) {
    this.teamId = pTeamId;
    final ClassABC classABC = new ClassABC(pTeamId);
    ...
    return myType;
}

Notice how the input parameter pTeamIdis assigned to the private data element teamIdin the first line of the method. Note that teamIdthere are getter and setter methods for this data item (which I did not bother to include for simplicity. Just know that they are the standard getter / setter pair).

So, I believe that I could write this method in different ways when I call the recipient of the data item that I just set, instead of using the input parameter passed directly, as in Method 1:

Method Option 2

public myType getSomething(final int pTeamId) {
    this.teamId = pTeamId;
    final ClassABC classABC = new ClassABC(this.getTeamId());
    ...
    return myType;
}

, / , , , , "" 1 2.

, JavaScript:

, Method Option 1, , , , " ...".

- ?

,

1) / // ?

2) ? ? ? .

, ? ( )?

.

+4
1

, null, . .

, .

, - getter setter. ( , ), ! ( -)

/.

+4

All Articles