Skip to content

Class Stereotypes

Ali Al-Ramadan edited this page Feb 2, 2024 · 6 revisions

A class stereotype is a simple description of the role of a class in a software system. Class stereotypes can be useful for a variety of software maintenance and evolution tasks. For example, class stereotype information can give clues on how different classes are interacting with each other.[1]

Taxonomy of Class Stereotypes

Class stereotypes can be classified into the following categories:

Class Stereotype Description
entity Encapsulates data and behavior. Keeper of data model and/or business logic. No controller methods.
minimal-entity Special case of Entity. Consists only of get, set, and command methods
data-provider Encapsulates data and consists mainly of accessor methods
command Encapsulates behavior and consists mainly of mutator methods
boundary Communicator with a large percentage of collaborational methods and a low percentage of controller methods. It also doesn't have many factory methods
factory Creator of objects and has mostly factory methods
control Provides functionality to control external objects. Consists mostly of controller and factory methods
pure-control Special case of controller. Consists only of controller and factory methods
large-class Contains a large number of methods that combine multiple roles, such as Data Provider, Commander, Controller, and Factory
lazy-class Consists mostly of get, set, and degenerates methods. Occurrence of other methods is low
degenerate Consists mostly of degenerate methods that do not read/write to the object's state
data-class Consists only of get and set methods
small-class Consists only of one or two methods
empty Has no methods

TABLE 2. Class Stereotype Classification.[5]

A given class may have one or more of these stereotypes. For example, a boundary data-provider class consists mostly of accessor and collaborational methods.

Rules for Class Stereotype Identification

To determine the stereotypes of classes in a given software system, we start by identifying the method stereotypes. This information is then used to calculate the class signatures. Class stereotypes can then be derived from these class signatures using a set of rules that map the class signatures' characteristics to the class stereotype taxonomy.[1]

Notation used in the rules:

  • {stereotype} is the set of method stereotypes of the type stereotype. For example, {get} is a set consisting of methods such as get, get collaborator, get incidental, etc.

  • {stereotype category} is the set of method stereotypes of the category stereotype category. For example, {accessor} is a set consisting of all accessors (get, predicate, etc), accessors collaborators (get collaborator, predicate collaborator, etc) and accessors degenerate (predicate stateless, void-accessor empty, etc). The set {collaborators} consists of all the collaborational methods (get collaborator, set collaborator, factory collaborator, etc). Thus, the set {non-collaborators} = {methods} - {collaborators}.

  • {methods} is the set of all methods in a class.

  • |stereotype| denotes the cardinality of the set {stereotype}.

entity

To identify the class stereotype entity, the following rules need to be satisfied:

  • They contain an accessor besides get and a mutator besides set
    {accessors} - {get} ≠ ∅ &
    {mutators} - {set} ≠ ∅

  • The ratio of collaborational to non-collaborational methods is 2:1
    |collaborators| / |non-collaborators| = 2

  • They can have factory methods but no controller methods
    |controller| ≠ 0

minimal-entity

To identify the class stereotype minimal-entity, the following rules need to be satisfied:

  • The only method stereotypes are get, set, and command/non-void-command
    {methods} - ({get}∪ {set} ∪ {command} ∪ {non-void-command}) = ∅ & |get| ≠ 0 & |set| ≠ 0 & ({command} ∪ {non-void-command}) ≠ ∅

  • The ratio of collaborational to non-collaborational methods is 2:1
    |collaborators| / |non-collaborators| = 2

data-provider

To identify the class stereotype data-provider, the following rules need to be satisfied:

  • It consists mostly of accessors
    |accessors| > 2 |mutators|

  • Low control of other classes
    |accessors| > 2 (|controller| + |factory|)

command

To identify the class stereotype command, the following rules need to be satisfied:

  • It consists mostly of mutators
    |mutators| > 2 |accessors|

  • Low control of other classes
    |mutators| > 2 (|controller| + |factory|)

boundary

To identify the class stereotype boundary, the following rules need to be satisfied:

  • More collaborators then non-collaborators
    |collaborators| > |non-collaborators|

  • Not all the methods are factory methods
    |factory| < ${1\over2}$ |methods|

  • Low number of controller methods
    |controller| < ${1\over3}$ |methods|

factory

To identify the class stereotype factory, the following rules need to be satisfied:

  • It consists mostly of factory methods
    |factory| > ${2\over3}$ |methods|

control

To identify the class stereotype control, the following rules need to be satisfied:

  • High control of other classes
    |controller| + |factory| > ${2\over3}$ |methods|

  • Accessor or mutator are present
    |accessors| ≠ 0 ∨ |mutators|≠ 0

pure-controller

To identify the class stereotype pure-controller, the following rules need to be satisfied:

  • Only controller and factory methods with no mutator, accessor, or collaborator methods
    |controller| + |factory| ≠ 0 &
    |accessors| + | mutators| + |collaborator| = 0

  • There must be at least one controller method
    |controller| ≠ 0

large-class

To identify the class stereotype large-class, the following rules need to be satisfied:

  • Categories of stereotypes (accessor with mutator) and stereotypes, factory and controller, are approximately in equal proportions
    ${1\over5}$ |methods| < |accessors| + |mutators|
    < ${2\over3}$ |methods|
    & ${1\over5}$ |methods| < |factory| + |controller|
    < ${2\over3}$ |methods|

  • Controller and factory have to be present
    |factory| ≠ 0 & |controller|≠ 0

  • Accessor and mutator have to be present
    |accessors| ≠ 0 & |mutators|≠ 0

  • Number of methods in a class is high
    |methods| > average + stdev

Note that average and stdev of number of methods are calculated per system. Their default values are 21 and 1 respectively in the stereocode tool.

lazy-class

To identify the class stereotype lazy-class, the following rules need to be satisfied:

  • It has to contain get/set methods
    |get| + |set| ≠ 0

  • It might have a large number of degenerate methods
    |degenerate|> ${1\over3}$|methods|

  • Occurrence of other stereotypes is low
    |methods| – (|get| + |set| + |degenerate|) <= ${1\over5}$|methods|

degenerate

To identify the class stereotype degenerate, the following rules need to be satisfied:

  • It consists of many degenerate methods
    |degenerate| > ${1\over2}$|methods|

data-class

To identify the class stereotype data-class, the following rules need to be satisfied:

  • Only the simple accessor/mutators get and set are present
    |get| + |set| ≠ 0 & |methods| – (|get| + |set|) = 0

small-class

To identify the class stereotype small-class, the following rules need to be satisfied:

  • Number of methods in a class is less than 3
    |methods| < 3

empty

To identify the class stereotype empty, the following rules need to be satisfied:

  • Number of methods in a class is 0
    |methods| = 0

References

[1] Dragan, N., Collard, M. L., & Maletic, J. I. (2010, September). Automatic identification of class stereotypes. In 2010 IEEE International Conference on Software Maintenance (pp. 1-10). IEEE.