Unit 7 Study Guide: Template Programming

7a. Demonstrate a detailed understanding of generic programming and principles in the standard template library (STL)

  1. What are the principles of generic programming using the standard template library?

It may seem surprising, but a goal of software developers is the 'elimination' of programming, or at least to reduce the amount of code that we must write to solve problems. The software development process is, at its core, problem solving. To do this, developers must identify commonality in programs, use abstraction to form (common) modules with usable interfaces for organizing and composing them, and develop techniques for adapting those modules to solve a large number of similar problems. They also need techniques for decomposing problems, so that the parts correspond to the modules. We have studied these ideas in this course: modularization, composition, hierarchy (or decomposition), and abstraction, and divide and conquer strategies. These ideas comprise the principles of generic programming.

Some specific principles of generic programming include object-oriented software development using classes and objects, inheritance, polymorphism, abstract classes, namespaces (in C++) or environments (in Python or Java), templates, and STL.

What is the STL? Define a template. An overview of these principles are presented in Kang's "Lectures 5 and 6".

 

7b. Demonstrate an understanding of various types used within the standard template library in C++

  1. Name some of the types in the standard template library for C++.

Templates use type variable – that is, variables that take types (e.g. integer, double, a class, etc.) – as values. "Notes for Lecture 9" addresses templates and summarizes the STL. Section 10.1.2 of Eck's "Introduction to Programming Using Java" also gives an overview of templates and the STL.

 

7c. Demonstrate an understanding of various types used within the standard template library in Java.

  1. Name some of the types in the standard template library for Java.

Java does not have templates, but it has features for generic programming, including interfaces, parameterized types, and a common set of parameterized classes for implementing common data structures. How do parameterized types in Java differ from templates in C++? For Java, STL-like classes are provided in the JCF (Java Collection Framework). What are some data structure classes in the JCF? Sections 10.1.3 through 10.1.5 in Eck's "Introduction to Programming Using Java" discuss this further.

Common classes stored in a library reduce programming effort and provide high quality module-building blocks for use in solving many kinds of problems. We should know the efficiency of these reusable components. Recall that generality is often a tradeoff with efficiency (determined from performance data and complexity analysis), and should be emphasized is a design decision made in the programming process.

 

Unit 7 Vocabulary

This vocabulary list includes terms that might help you with the review items above and some terms you should be familiar with to be successful in completing the final exam for the course.

Try to think of the reason why each term is included.

  • Abstract class
  • Compile-time
  • Generics
  • Generic class
  • Generic programming
  • Inheritance
  • Java Collection Framework
  • JCF
  • Overloading
  • Namespaces
  • Parameterized type
  • Polymorphism at compile-time
  • Polymorphism at run-time
  • Run-time
  • Standard Template Library
  • Template
Last modified: Wednesday, July 17, 2019, 6:12 PM