Pedagogical Pattern #46
Big Picture on a Small Scale (BPSS) Pattern

(Version 1.0)
Kerstin Voigt
California State University
San Bernardino, CA 92407
voigt@csci.csusb.edu

Intent:

To focus the teaching of the object-oriented paradigm (OO) in weeks 1-4 of a 10-week quarter on Computer Science I on introducing the notion of an object in a way that is informal, appealing to students' intuitions on everyday objects, and does not shy away from introducing the central OO concepts such as aggregation, inheritance and polymorphism.

Motivation:

I strongly believe that the first 1-4 weeks (typically 8 1+-hour lectures with 3-4 lab sessions) are crucial in setting up students' mind sets with regard to OO. If objects are not introduced and emphasized as the artifacts whose manipulation is at the center of programming, the remainder of the course, and subsequent courses tend to suffer from the continued and repeated struggle to eliminate bad (e.g., non-OO) habits and misconceptions.

Audience:

The pedagogical pattern is meant to govern the very first weeks of teaching a a "Computer Science I" course. It is assumed that students are complete novices to the object-oriented paradign, and possibly computer programming in general.

Structure:

More discussion and insight is needed on what we could call "OO teaching" (how about OOT?). OO teaching should put objects and related concepts like aggregration, inheritance, and polymorphism in the foreground. That entails that these topic are introduced from the very beginning, instead of being banned to the final chapter (or even appendix!) of introductory OO textbooks. It also entails that the introduction of classes and objects --when included in earlier chapters-- not be given in an overly gentle and timid fashion, only to be followed by chapters on functions, conditionals and iteration, before finally hitting the student over the head with a linked list (frequently, topics of inheritance and polymorphism are omitted entirely). First we go too slow, then too fast. No wonder, many students do not manage to get on track. I believe that more conducive to learning OO would be the presentation of topics in roughly this order:
  1. Objects, Classes, object state
  2. Aggregation
  3. Object behavior, member functions
  4. Inheritance
  5. Polymorphism
  6. Conditionals
  7. Iteration
  8. ......

The first exposure to functions will be in form of member functions ("what the object does"). Many students tend to have difficulties with functions initially; maybe the purpose of a member function will seem more intuitive and facilitate the understanding of the benefits of functions in general. Conditionals and iteration will be motivated as constructs that allow the specification of more richer object behavior. In other words: let's not practise conditionals and iteration in the body of a "big main", but in the body of a member functions; e.g., if-then-else comes in handy if a member function is to ensure that no illegal/nonsensical object states be defined; iteration will allow the specification of object behavior that is repetitive.

If students are instructed from the very start to associate most (or, initally all) program behavior with small-bodied member functions belonging to objects, there will be less of the typical cramming of "everything the programs is to do" into a "big main".

Consequences:

Students that will emerge with significantly greater familiarity, comfort and skill in object-oriented analysis (OOA), design (OOD) and programming (OOP).

The key to this style of teaching, will lie in its wholistic and practically "zero-alternative" approach to learning about the full spectrum of OO concepts in the earliest stages of learning to design and implement OO programs. Students will have embraced a sizable problem solving and programming paradigm by having been given the "big picture" (the OO paradigm) on a small scale (through small, intuitive examples).

Students will model data as objects because that's how problem-specific data were represented from the start. Students will express program behavior through member functions associated with objects because that's how objects were brought to life from the beginning. Students will use inheritance because that's how one could avoid restating the already established. And lastly, students will understand polymophism as a way of making adjustments to inherited behavior that has become inappropriate in the more specialized context.

Implementation:

The suggested approach to OO-teaching (I suggest: OOTch) essentially consists of not much more than a reordering of your typical Computer Science I and II textbook topics. Any instructor experienced with OO will be able to adopt this approach.
The here presented suggestions address the first 1-4 weeks of OO teaching only. Beyond those weeks, a course may follow any one of numerous good textbooks on OO programming, with the added advantage that most likely more interesting examples than those presented in books can be dealt with. For example, no longer will sorting have to be taught as sorting an array of integers (how boring!), but sorting may be applied to an array of student_records or houses_for_sale, or just about any artifact whose object-oriented representation at this point comes natural to the students. What will be required of the instructor adopting this approach is the consistent and repeated reinforcement of the OO paradigm as a way of approaching the problem. For every new program, the same kinds of questions should be discussed in class:
  • What are the objects in this problem?
  • What are the important parts and properties of the objects?
  • Are these primitive parts (representable as int, char, ..) or are these parts objects in their own right?
  • What do these objects do? What behavior should they meaningfully exhibit?
  • Have we seen/dealt with/programmed objects before that are very similar? Do the new objects differ from those in that they have additional parts or properties?
  • If we let our new objects adopt the parts and behaviors from already defined objects, are the adopted ("inherited") behaviors still appropiate for the new objects, or should some behaviors be modified?

    Answering those questions each and every time will have students practise looking at a problem with "OO eyes". It will naturally have them work with aggregation, inheritance and polymorphism.
    As the resource included below hopefully demonstrates, it is quite easy to come up with simple and intuitive examples.

    The first four weeks of teaching Computer Science I in the suggested object-centered fashion are sketched out below. Several concrete object classes, specified in C++, are included as sample resources. Two things should be noted here. (1) You may view the use of C++ as a notation/shorthand to allow a less verbose presentation of the ideas. (2) You may view the bits of C++ code as parts of concrete class/lab exercises that demonstrate how in informal examination of objects in some problem domain is being translated into the syntactic constructs of a concrete programming language (Contrary to some, I believe that learning about syntax (which is generally agreed on as being the "easy part") does not have to be in the way of teaching design; the successful compiling and running of a program can be seen as valuable verification of one's design.)

    Week-1:

    The class informally discusses the notion of an "object" as we know it from our daily experience with the physical world. The instructor may bring along some artifacts and let students describe them. Discover that many objects are composites, and are readily described in terms of their parts and properties. Looking ahead to subsequent lectures, students may also be instructed to discuss the kinds of behaviors (= things to do) that different kinds of objects are expected to exhibit. The discussion should be held at an informal level that allows all students to contribute.

    Next discuss the notion of a "program" as a set of instructions that will have the computer manipulate data (= pieces of information = objects) to arrive at solutions to a given problem. A program needs to be informed of the kinds of objects (parts and properties) to manipulate. Since computers are not capable of understanding natural languages, objects are described to the program in a socalled programming language, C++ being one of many options. The previously informally discussed description of a type of object is now written out using programming language syntax. At this point, students are also taught that the programing language knows about several basic types of objects, from which all composite objects are to be built. These basic types are int, float, char etc.

    An example for a resource for Week-1 defines a "house for sale" object that lists the number of bedrooms, square feet, asking price, address etc. as parts and properties. The corresponding class definition is kept simple in that all parts and properties are basic types of objects, and declared public (a minimal explanation of public should suffice at this point).

    Week-2:

    The House_for_object is reexamined, and the discovery of other parts of the house is encouraged. Students will be led to suggest parts that are not representable as basic objects but are objects in their own right. For example, the house for sale can come with a garage (described in terms of how many cars it fits), and appliances (described as being of a brand name, and either powered with electricity or gas). Let students experience how new objects Garage and Appliances are defined in analogy to House_for_sale.

    Effectively, the notion of aggregation has been introduced. In addition, it is fairly easy to lead over to the basics of encapsulation. At this stage, suffice it to say that parts and properties defining an object are precious and vulnerable to corruption (how about somebody indicating a negative number of bedrooms, or filling in some fantasy brandname?). Labeling parts and properties as protected will safekeep the state of an object.

    Once the defining parts of an object have been rendered invulnerable, they have also been rendered inaccessible. Lead students to understanding that a carefully crafted interface will allow us to access and manipulate the parts and properties of an objects in a fashion that is intentionally restrictive; it allows only what is needed and meaningful, and disallows acts of corruption. The interface will initially be minimal and consist of exactly two member functions (= "behaviors") per part or property: one function that allows the assignment of values to the part, and one function that allows the access/retrieval of the part's value.

    Week-3:

    Week-2 will have motivated the notion of a function. While other types of functions exist, no harm is done in letting students believe that a function is something that an object "does". In fact, the lack of any alternative to OO will counteract the development of non-OO programming habits from the start (... there will be no "big main()", and their won't be function calles other than calls to member functions; that in turn means that all data has been conceptualized and designed as objects).

    Staying with the design of a House_for_sale object, students will find the interface too restrictive. Encourage the discovery of other meaningful member functions. For example, suggest that the house be able to avertise itself. A new member function House_for_sale::advertise() could print out a brief statement such as "This beautiful new home has 4 bedrooms and ...". Notice that beyond the syntax for class definitions and member functions, only standard input and output have to be taught which leads to inevitably very simple member functions. Next encourage students to discuss in more discriminate terms what kinds of houses may be up for sale. The notion of a "fixer-upper" may come up. Let students discuss the notion of a "fixer upper" compared to the earlier notion of a house for sale. Are there differences? Let students discover, that all parts and properties describing a house for sale, also apply to a fixer-upper, yet there is additional information that is typically provided along with the latter (e.g., the year it's been built, and whether it has lead paint and asbestos). Conclude Week-3 by having students write a C++ specification of Fixer-upper in analogy to the most recent definition of class House_for-sale.

    Week-4:

    Discuss with students how it felt to be writing the specification for a class Fixer_upper. Did they find it repetitive at all? Would they want to repeat this experience for other types of houses on sale? Wouldn't it be nice, if you could tell the program that Fixer_upper is just like House_for_sale with some additional features? Having thus triggered their curiosity (and fed their budding discontent with the repetive exercise), they will be receptive to the notion of inheritance. A Fixer_upper can indeed by defined as a specialized subclass of House_for_sale, and not much additional syntax to express this relationship is needed. Demonstrate to students how easily the subclassing is expressed, and stress the convenience of having to add C++ specifications for only the additional features of the subclass.

    Now examine the subclass Fixer_upper more carefully. It inherits all parts, properties and member functions from its superclass House_for_sale which is a good thing, except ... Point out that Fixer_upper also inherits member functions House_for_sale::advertise(), and that the function effectively advertises the object as "This beautiful new home ...". . This is clearly inappropriate for objects in the fixer-upper subclass. A fixer-upper should still be able to advertise itself, and the inheritance of this capability makes perfect sense. However, the messsage of the advertisement should be a different one. After students have appreciated the discrepancy, they will be receptive to the possiblity of redefining the message. Teach students that the inherited member functions advertise can be {\em overwritten} as part of defining Fixer_upper. The function retains the old (and entirely appropriate) name, but its body is changed to, say, "This affordable fixer-upper with great potential ...". And thus, at the week of Week-4, we have covered basic forms of polymorphism. The rest is reinforcement... Other standard topics of programming (conditionals, iteration, arrays, pointers, etc.) can now be taught in the usual sequence, but with the added motivation of allowing the expression of more sophisticated object behavior.


    Home Project
    Leaders
    Pedagogical Pattern
    Format
    Evolution of a
    pedagogical pattern
    Sample
    Patterns
    Publications
    Subject
    Index
    Learning Obj.
    Index
    Teaching/Learning
    Element Index
    Alphabetical
    Index
    Author(s)
    Index
    Contact
    Us
    Previous pattern Search This Site Next pattern