Teaching OOD and OOP through Java and UML
in CS1 and CS2
Philip R. Ventura, Jr., M.S. and Carl Alphonce, Ph.D.
SUNY Buffalo
Abstract
At SUNY Buffalo we have adopted a strong design philosophy for our CS1 and CS2 classes. The approach in CS1 is to use dual introductory strategy, pairing objects first with early analysis and design grounded in graphical programming assignments. A subset of the UML’s class diagrams is used. OOP has become thematic in CS1, i.e. topics such as, objects and classes, the UML, inheritance, polymorphism, interfaces and design patterns are covered before imperative constructs such as selection, looping and arrays.
In CS2 the theme is continued utilizing semester-long group projects broken into 3 separate deliverables. Students are encouraged to utilize good programming practice through a process of peer review.
Current initiatives include the trial of pair programming in CS1 and the use of an in-house developed UML tool.
In the fall of 1998 the Department of Computer Science and Engineering created CSE115: Introduction to Computer Science I for Majors (CS1), along with its follow-up course CSE116 (CS2). This was the first time the department offered an introductory course solely for computer science majors; non-majors are serviced by a distinct course sequence. More significant was that all introductory programming courses would be taught using Java. It was quickly discovered that students experienced greater difficulty in these Java versions of the introductory courses. This stemmed from a number of factors. Java’s more object-oriented nature meant that much code needed to be considered as “boilerplate” until later in the semester. Further, the change later in the semester from imperative to object-oriented programming paradigms seemed to confuse many students.
We began experimenting with introducing object-oriented concepts earlier with encouraging results. This led to the current treatment of CS1 as an object-oriented programming (OOP) and design (OOD) thematic course. Both OOP and OOD are introduced in the very beginning of the semester and utilized throughout.
The guiding philosophy in CS1 & CS2 at SUNY Buffalo is that object-oriented programming and analysis is thematic to these courses. This entails fundamentally the philosophies of objects first and early design. However, these concepts alone often fall short in terms of implementation, especially in recent texts. Many textbooks advertise an objects first approach. However, our experience has revealed that while in fact objects and classes are introduced relatively early, they are often followed up directly with chapters on imperative concepts and treated as orthogonal. Instead we impress upon students the importance of the object-oriented paradigm to problem solving and address all other issues in the course in such terms. This effectively leads to a unified approach to OOP.
Through the addition of class diagrams and design patterns we encourage students to think in terms of design rather than a particular code solution. This eases discussions of more complex interactions in CS2, where instructors can simply show UML diagrams and/or the appropriate design patterns used by a system. Further this has the added benefit of providing students a cognitive language to express designs independent of a particular programming language. This eases the transition of our students from CS2 to follow-up courses which use C++.
Finally, student projects are graphical in nature. This speaks to the more sophisticated student population many of whom are not used to command-line utilities. Additionally, having graphical objects from early on helps to reinforce the notions of objects vs. classes and other concepts.
CSE115 (CS1) introduces students to the distinction between objects and classes at the very beginning of the course. Students are further taught the fundamental relationships between classes: composition, dependency and association, and how to recognize each in a problem domain. At the same time the class box notation from the Unified Modeling Language (UML) is introduced along with appropriate arcs. However, it should be noted, that ours is a simplification of this notation originated at Brown University. All arcs, for instance, are directed and imply a one-way relationship. The students are provided with specific semantics for each relation and taught the translation of such arcs to Java code.
Their knowledge is then built upon to include concepts such as inheritance, polymorphism and interfaces in general object-oriented terms, in the UML and in Java.
For each new concept students are given projects to exercise their knowledge. The importance of working with class libraries and within frameworks is stressed by providing the students with various classes with which to assemble their programs. Students gain the ability to distinguish when and how to re-use code as well as when to write their own code.
After the introduction of general OOP and OOD, students are introduced to design patterns. Rather than cover all of the original 23 design patterns, we cover a handful of simple patterns, including Proxy and State. The first semester teaching this material we were apprehensive of how well students would take to the concept of design patterns. Our fears were allayed when we found students identifying places where they could appropriately employ design patterns in projects where we had not intended design patterns to be used.
In CSE116 (CS2) the OOP/OOD foundations laid in CS1 are built upon. Students are required to complete a large semester long project. This project is broken into 3 distinct stages. Students are not told what the project will be like by the end of the semester. Instead they are given the specification for the first stage and told that subsequent stages will build on it. This encourages students to use modular designs.
Further, students are required to work in groups of 3-4 (selected by the instructors) on the projects. They are instructed on the use of interfaces and stub classes as a technique for separating the programming. Essentially they are encouraged to design as a group, but program separately.
Upon turning in the first stage, the groups are given the stage 2 description along with a different group’s stage 1 solution. The group must then build their stage 2 on the other group’s first stage. Further part of their stage 1 grade derives from comments about their own design from the other group who is using their code.
From this strategy, a number of benefits emerge. Students are encouraged to develop modular design, since they do not know along which dimensions they will need to extend. Further, their code needs to be well-documented both in terms of commenting and naming conventions for the other group to develop on it. Finally, it allows for students to see different design approaches to the same problem.
For example in the spring of 2001, CSE116 students wrote a program to play the game Scrabble. In stage 1, students were required to build most of the game logic including placing tiles on the board, and scoring. However, in stage 1 no graphical user interface was to be provided. This was to encourage the use later of a Model-View-Controller solution. Stage 2 added the GUI along with lookup of words in a dictionary file. Stage 3 required the students to make the program a distributed network game. This was accomplished through the use of Java’s remote method invocation mechanism.
Overall students were successful in their endeavors and had felt they had learned much.
This semester we are undertaking two modifications to the approaches outlined above in CS1. One is the use of a UML tool with a code generation utility and the other is pair programming.
This summer the authors obtained funding to create a Java-based UML tool for use in CS1 & CS2. The problems with current tools were that 1) they used full-blown UML which is unwieldy for students at this level and 2) the Java-based ones were too slow. This resulted in the creation of our QuickUML tool which allows students to create class diagrams using the syntax and semantics taught in CS1 and to generate the code from such diagrams in either Java or C++. We are currently evaluating the utility of such a tool over hand-drawn diagrams. We are investigating whether using such a tool results in quicker development time and better designs as well as any possible deleterious effect on coding performance.
Pair programming is a technique from Extreme Programming in which two individuals program together. The individuals take turns being “driver” and “navigator.” The driver sits at the keyboard typing code, while the navigator sits with him or her and directs the process through asking questions. We are investigating the effects of using pair programming in CS1, especially whether the use of pair programming results in quicker development time and better designs and whether it hinders students’ ability to program alone.
Phil Ventura has been teaching several courses on Java and Object-Oriented Programming and Design to computer science majors and non-majors as well as industry professionals for the past 4 years. He holds the position of Lecturer in the Department of Computer Science and Engineering at SUNY Buffalo. Phil earned his Master’s Degree in Computer Science from SUNY Buffalo in 2000. Currently he is pursuing his Ph.D. in Computer Science in the area of mobile computing. His thesis work involves the creation of an Object-Oriented framework for Place in Mobile Systems and will be implemented in Java. He currently teaches CS1 and CS2 at SUNY Buffalo and has spearheaded their reorganization. Additionally he is active in research on pedagogies for OOP/OOD in CS1 and CS2.
Carl Alphonce is a Teaching Assistant Professor in the Department of Computer Science and Engineering at the University at Buffalo, State University of New York. He received his doctorate in Computer Science from the University of British Columbia in 2000. His research interests include computational linguistics, in particular modeling human sentence processing, and computer science education, investigating how best to teach object-oriented design and programming in CS1 as well as how the use of technology can be used to increase learning and decrease costs in large-enrollment service courses.