A setter subroutine requires a parameter which represents the new value of the state.
For example, the Player class now contains a number of mutator behaviors. Following convention, the names of these behaviors begin with the word Set.
In a class diagram, the format for a setter behavior(subroutine) looks like this:
Visibility SubroutineName(Parameters: DataType)
...as can be seen in the Player class example:
+SetName(NewName: String)
The implementation (code) for a mutator, reads the parameter that is passed to it and updates the value of the state with the value of the parameter. In other words, the SetName() function will read the String parameter passed to it and then change the value of the Name state.
An mutator behavior has visibility of Public.
No comments:
Post a Comment