Pedagogical Pattern #44
Responsibility Driven Class Development Pattern
(Version 1.0)
Douglas B. Smith
University of the Pacific
Department of Computer Science
Stockton, CA 95211 USA
dsmith@jarl.cs.uop.edu
Intent:
To introduce students to object design concepts when developing commonly used classes.
Motivation:
When encountering frequently used classes, the student is usually presented with the list of attributes and member functions, challenged to code the class and then write a program using the class. This does not develop object "thinking". The Responsibility Driven Class Development
pattern teaches introductory object design concepts and reinforces object thinking.
Applicability:
Use this to develop classes used in introductory courses - strings, stacks, queues, lists, linked lists, graphs.
Structure:
- 1. Responsibilities: using the CRC card approach, determine what the class should know, what are its reponsibilities and its collaborators.
- 2. Create a UML diagram for the class and document member functions.
- 3. Identify and discuss "small" use cases to refine the class and develop member function parameters.
- Does the class know enough, have enough responsibility to ... ? For example, in developing a list class, can we search the list for an item? can we add an item to the list? What data does the class need to receive to carry out the responsibility?
- 4. Implement the Class
- Use analogy, visual, and abstract representations to motivate code development. Test the class with a test harness.
- 5. Use the Class on a significant use case.
Consequences:
In the early courses where this approach is used, the students pick up the language and elementary object design techniques. With repetition, the students get comfortable with CRC cards, responsibility driven design, simple UML diagrams and the idea of use cases.
Implementation:
It's important to avoid over directing the initial CRC discussions. For the pattern to work, the instructor must avoid comments like "we must be able to push data on a stack - right?". Let the students come up with their ideas. If you then move to a text book (pre-designed) class, you can
discuss how the responsibilities identified by the students are (or are not) met by the class in the text.
The students can work together to develop a test driver that exercises all of the classes responsibilities. This gives everyone a way to verify the implementation of the class before using it in a larger project.
Example Instances:
This pattern has been used effectively in data structures and algorithms courses to teach: Strings, Stacks, Queues, Lists, Search Trees, Graphs, Hashing