Imperative Programming II: 2012-2013
OverviewThis course starts with an introduction to the basic concepts and techniques of modular program construction and Object-Oriented Programming (OOP). It continues with one modest-sized case-study that introduces some of the basic OOP programming idioms (Design Patterns) in realistic settings.
There are three main ideas: encapsulation, that programs should be built from objects that satisfy a coherent specification and hide the details of how that specification is implemented; object identity, that each object has a distinct identity, so that multiple objects can co-exist and interact with each other; and polymorphism, that objects that implement the same interface can be used interchangeably to give a variety of behaviours.
There is a correspondingly heavy use of practicals to develop understanding of OOP in general, and the use of Scala in particular.
Learning outcomesAfter studying this course, undergraduates will be able to:
- Develop Scala programs with multiple classes that follow the principles of objected-oriented programming.
- Organise multiple related classes using appropriate inheritance mechanisms, such as traits and abstract class, and basic design patterns.
- Use generics to develop polymorphic programs, and explain the differences among generics, subtyping polymorphism and operator overloading.
- Read and modify medium-sized objected-oriented programs.
- Use the Collection/Iterator framework and explain the cons and pros of the underlying design principles of the framework.
- Introduction. Reminder of the Scala language. Objects and functions in Scala.
- Inheritance. Subtyping. Overriding. Dynamic dispatch. Encapsulation.
- Traits and mix-in. Linearization. Stackable modification.
- Pattern matching. Extractors.
- Circuit simulation example. Simultaneous use of functional and imperative features.
2: Polymorphism and Advanced Types (Lectures 7 - 10)
- Three types of polymorphisms in Scala: generics, overloading and subtyping. Covariance and contravariance.
- Abstract members and abstract types.
- Implicit conversions and parameters.
3: Collections (Lectures 11 - 16)
- Programming with the Scala Collections library. Iterators.
- Hash tables.
- Design of the Scala List library.
- Design of the Scala Collections library.
Language features for structuring classes in Object-Oriented Programming: inheritance, abstract class, dynamic binding, and mix-ins (traits in Scala). Three kinds of polymorphism in OOP: subtyping polymorphism, overloading, and generics. Basic design patterns. Case studies: circuit simulation and collection framework with associated iterators.
We recommend the following book:
- Martin Odersky, Lex Spoon and Bill Venners, Programming in Scala, 2nd edition, artima.
This book, the lecture slides and occasional references from the slides will form good reading materials for this course.
If students want to go deep into the materials covered, they will find the following books useful:
- Barbara Liskov and John Guttag, Program Development in Java, Addison-Wesley.
- Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley.
- Peter Sestoft, Java Precisely, 2nd edition, MIT Press.
The first book was the recommended text of this course before the 2012/2013 academic year. Although the course was changed, Chapters 1-10 of the book are still relevant to the lectures. The second book is a well-known reference on design patterns, which all OOP developers should know eventually. The last has a good description of language features of Java. Scala is often used together with Java, so this book will be useful when students build or modify real-world Scala programs.