Position paper for OOPSLA '96 workshop
"Teaching and Learning Object Design in the First Academic Year"

A Simple OO System Pattern to

Introduce OOP with Design
Erzsébet Angster
Dennis Gábor College for Information Technology
SZÁMALK Education and Consulting Center
Department of Programming
1115 Budapest Etele út 68, Hungary
e-mail: angster@gd-szamalk.hu

Abstract

There is no doubt, that designing and implementing OO systems are equally important in learning OO technology. Students must see the system's logic from above and they must see the outcome of their work, that is to say the running program. In addition they must feel the importance of the reusable library. The systems must be simple enough to develop it from the beginning to the end.

Our students make a static modeling first, where the system typically consists of an application object and some interface objects. They get a window and a container class for reuse, and they have to build a system, where there are several kinds of windows controlled by an application object. The windows are specialization of the reusable window, and they are linked to the application with the reusable container object. My experience is, that varying this simple system pattern students can learn the basic OO concepts very effectively. Later they can build on this knowledge when learning the dynamic aspects of a system, or solving more complex problems in the OO paradigm.

The Simple OO System Pattern

Even the simplest application has an application object and one or more interface objects, which are usually windows on the screen. Furthermore, if there are more than one objects in an application, there must be some associations between them. The associations can be implemented with simple references or, in most cases, with container classes such as list, array, set, dictionary, tree, etc. Consequently window and container classes are the most frequently used classes in any applications. From this fact I got the following idea:

Students begin learning OOP by making applications built up from these simple elements, where application controls different kinds of windows. They build a static model - they produce the object diagram and the class diagram for every problem. Since the students work on basis of a pattern, they can concentrate much easier to the OO concepts, such as encapsulation, classification, aggregate and acquaintance associations, inheritance, polymorphism and late binding. If the students understand these concepts and can build the static model without any difficulty, I'm sure that they can go further easily to make dynamic modeling and to solve much more complex problems.

The students activities during the OOP course:

1) Students develop a TWindow class which they use and test. Finally they get the improved TWindow class from the teacher. From now onward it is compulsory for the students to reuse this class.

2) They make an application, which controls a constant number of windows. Associations are simple references now:



3) They specialize several windows from TWindow and use them in their application in different ways. They get familiar with static and dynamic methods also. They continuously produce the object and the class diagram.

4) Students create a simple container class, the TList. They use and test it. Finally they get the improved TList class from the teacher for further reusing.

5) They implement the 1:n association with the TList class. They put many windows in their application in different ways. They inherit the TWindow from THead, since an object can be added to the list only if it has a head.

Let's see the general outline of a possible object and a class diagram of a simple system. Assume, that the windows are ordered in some way:




Later TList can be omitted from the class diagram, since it is an implementation class only. Though it is very important to see the implementation details at the beginning of learning OOP. The class diagram without implementation details:

Note:

In spite of the pattern's simplicity, there are infinite variations of problem specifications to find out. One of them is the following:


Put some windows on the screen, which are all blue, their size is 10*20 and they display every string in capital letters. Put some other windows on the screen, which are all gray, their size is 20*10 and they display every string in small letters. The windows are ordered on the screen by the X coordinate.


When pressing F6, make the next window actual.

When pressing F7, write your name to the actual window.

When pressing Alt-F4, application terminates.

Of course we can give more complex problems, where some entirely new classes are to find out. As a final example, let's see the following problem specification:


The program's task is to operate newscasters and clocks. For the sake of simplicity, they appear on screen. The height of the newscaster is 1 character, and it shows text one character further in every interval. Upper left corner, width, colors, the text and the speed (in sec/100) are given at initialization time.

The clock shows the actual time (hour, minute, sec, and sec/100) in every definite interval. The size of the clock is 13x1 characters, it's color is gray and brown. Upper left corner and the refreshing time (in sec/100) are given at initialization time.

The newscaster and clock determined at the beginning of the program are to operate continuously until a key is pressed.


Students can sign the nouns and verbs to analyze the text and to find out the possible objects and responsibilities. In this problem the application have zero or more newscasters and zero or more clocks. The newscaster and the clock are both timers, since they do something periodically. They are also windows, since they must display their states. So they derive from two classes at the same time. This is solvable only if the programming language supports the multiple inheritance (Solution A). Let's assume a language with only single inheritance. In this case one solution is to dissolve the multiple inheritance with putting classes below each other (Solution B), but a better solution is, if both the newscaster and the clock has an own display connected to them (Solution C). The students make an analysis, and they usually find out one of these three solutions. Of course it is very important to discuss the strength and the weakness of their solution every time.


Problems in teaching OOP for beginners

Students can think in objects, though making a good and reusable model needs learning and a lot of experience. I think, that object-oriented analyses is applicable from the very beginning, since an analyses model comes from the real world. The concepts to understand are mainly encapsulation, responsibility, collaboration, association, messages and scenarios. The situation is not so easy in the programming paradigm. While an OO analyses model is close to the human, the design model is closer to the computer. The reason is, that the design model is an expansion of the analysis model so that it is fleshed out with implementation details. Implementing the simplest system needs a lot of computer knowledge. It assumes that students are able to do the following:

Data and algorithms are on the first level of abstraction - in the case of objects the abstraction is one level higher. This means that methods must be qualified, not to mention the inheritance tree. Isn't all this too much for a beginner?

Our scheme

In our college students have the following courses on the Software Engineering branch which are directly related to OO technology:

As you can see, students have programming for the whole of the first year. The programming includes also OOP, which serve as a base for Object-Oriented System Development.

How do we teach programming?

First we teach a demanding structured programming, where we put stress on design, and the evergreen concepts such as modularizaton, encapsulation and code reuse. There we teach the basic programming concepts such as:

While teaching these concepts in a structured manner, we speak about OO technology, and we show some very simple classes. After this part of the programming - which is the first semester now - comes the real object-oriented programming, presented previously. Further data structures and algorithms we teach with OO technology.

Comparison

Rick Mercer teaches the OOP for beginners also in a mixed manner (ECOOP panel, see references). He integrates only some object technology into the first course. I also think, - though I'm not sure, - that it is not possible to teach the pure OO technology for beginners. The reason is firstly that the computer hardware is not object-oriented itself, secondly that not all the languages are purely object-oriented till now.

References

Rick Mercer: Characteristics of an „Objects Early" Approach - ECOOP'96 panel session: Object-oriented Programming in Introductory Courses

Biography

Erzsébet Angster

Dennis Gábor College for Information Technology

SZÁMALK Education and Consulting Center

I'm the head of the Programming Department and the leading teacher of the following courses:

Since 1990 I develop OO courses. I try to put emphases on the OO design from the very beginning of the course.

Books published in Hungary: