Object-Oriented Programming

Free-Function Stereotypes

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

UML Stereotypes

Code Stereotype

  • A label we give to something to further distinguish it
  • Will look into method stereotypes and class stereotypes later in the course
  • Here, we will look at them from the perspective of free functions

Why Categorize into Stereotypes?

  • Functions of a particular stereotype share many characteristics and are more similar
  • Make sure we have explored the full range of what we can use
  • Shorthand for documentation

Free Function Stereotypes

  • Accessor::property
  • Accessor::predicate
  • Mutator::command collaborator

Mutator::command collaborator

  • Executes a change of the IN/OUT parameters

Accessor::property

  • Returns information based on IN parameter values

Accessor::predicate

  • Returns a Boolean result based on IN parameter values

Accessor: Extract Predicate

  • Parameters are all IN
  • Must pass all data directly used in the condition
  • Useful for even short conditions as it gives them a name
  • Often used in refactorings

Accessor: predicate use

  • Often extracted from code with complex conditional statements

Accessor: predicate naming

  • Set of standard terms that everyone knows means a predicate
    • empty(), contains()
  • If not standard term, then verb form is often is
    • isDone(), isPDFWord()
  • Other verb forms depends on context
  • Do not include the parameter or return types in the name, e.g., no bool
  • Never use the term “returns” in a function name