Role of a Class

- Classes serve a variety of roles
- Good design: Each class fulfills a small number of roles in the system
- Helps with design, comprehension, addition of new features, etc.
- Purpose is not to label for label's sake, but to improve design
- Note: Over the long term, even well-defined classes and roles tend to be mixed
Class Stereotypes

- Explicitly mark the class with its primary role and purpose
- Need a set of standard class stereotypes
- Most common is CBE (Control, Boundary, Entity)
- Classes also fulfill roles in Design Patterns
Qt Example

CBE: Boundary Class

- Handle communication between external and internal parts of the system
- External? User interfaces, external systems, external databases, etc.
- Typically, a different boundary class for each external interaction
- Only works when the internals need to access the externals or to alert the internals that an external has a request or made a move
CBE: Entity Class

- Storage
- Model the data used by the system
- Perhaps includes a little behavior associated with the data
- Passive class. Only works when called.
CBE: Control Class

- Controls the other classes. Makes things happen.
- If objects are dynamically created and destroyed in the system, the control class does it
Reality
- In small systems, the cost of a class for each role may not be warranted. However, in non-trivial systems, it is well worth it
- The CBE categories are somewhat broad and perhaps not fine-grained enough
- Real classes will often support many roles
- Changes to a system often lead to blurred roles
Example

Class Stereotypes
- An extended set of class roles/types Dragan, Collard, Maletic'10
- More fine-grained stereotypes
- Reflect actual use in real-world projects
Taxonomy
- Data-centric
- Entity, Minimal Entity, Data Provider, Commander
- Behavior-centric
- Boundary, Factory, Controller, Pure Controller,
- Bad Smell
- Large Class, Lazy Class, Degenerate, Data Class, Small Class
Data-centric Class Stereotypes
- Entity
- Minimal Entity
- Data Provider
- Commander
Class Stereotype: Entity

- HippoDraw Class Range
- Holds the data model and/or business logic
- Typically contain accessors and mutators in
various proportions
- Might have a variable percentage of collaborational methods (up to 2/3)
- They do not have controller methods
Class Stereotype: Minimal Entity

- Entity with only get/set and command methods
- A special case of Entity that has only
get/set and command methods
- It encapsulates very trivial entities (e.g., Point)
- Considered separate because it is a very simple class that does not require much effort to comprehend
- Can also be considered a Lazy Class
Class Stereotype: Data Provider

- Holds data and mainly consists of accessors
- A high percentage of the methods are accessors
Class Stereotype: Commander

- Holds data and behavior and mainly consists of mutators
- A large part of the class’s behavior is implemented in command and non-void-command methods, which execute complex changes to the object’s state
- The changes may also involve objects of different classes.
Behavior-centric Class Stereotypes
- Boundary
- Factory
- Controller
- Pure Controller
Class Stereotype: Boundary

- Communicator in a system and has a large percentage of collaborational methods
- A low percentage of controller and not many factory methods
Class Stereotype: Factory

- Creator of objects with mostly factory methods
Class Stereotype: Controller

- Mainly processes data of external objects
- Updates an entity/model working mainly outside of itself
- Has almost all controller and factory methods
Class Stereotype: Pure Controller

- A special case of controller
- Controller that only works on other objects
- A strong candidate for the bad-smell God Class if it is a standalone class and consists of many methods
-
Bad Smell
- Large Class - Many methods and many roles, e.g., Data Provider, Commander, Controller, and Factory
- Lazy Class - Almost all get/set methods. May have a large number of degenerate methods
- Degenerate Class - Half or more of the methods are empty
- Data Class - Only get/set methods
- Small Class - A class with only one or two methods
Frequency Distribution

Patterns
