Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
Modern C++ design : generic programming and design patterns applied
Alexandrescu A., Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 2001. 323 pp. Type: Book (9780201704310)
Date Reviewed: Mar 18 2003

One of the main strengths of the C++ language is that it allows you to use templates in order to construct generic libraries and classes; you do not need to specify the type of parameter that is passed or returned from a class or its methods. This generic programming, when applied to the design of a program or library using constructs given in the Gamma et al. book [1], provides you with a toolkit of generic design patterns. These patterns are the subject of this book, which is destined to become a classic.

The book is divided into two parts. The first part (four chapters) considers generic programming techniques, such as policy-based class design, compile-time assertions, type mapping and selection, type traits, typelists, and allocating memory for small objects. The second part (seven chapters) addresses some common design patterns in terms of generic programming. Patterns considered are the abstract factory, command pattern in terms of functors, singletons, double-checked locking (when considering multithreading with the singleton pattern), object factory, visitor, and the prototype design patterns. In demonstrating the use of generic programming with regard to design patterns, the author partly constructs a library, named Loki.

A short appendix, which is one of the best I have read on the topic of C++ multithreading considerations and techniques, is provided towards the end of the book. The appendix is followed by a bibliography (this would be a great resource, if only the author had annotated it), and a reasonable index.

The first chapter considers policies: C++ idioms that facilitate flexible designs. These are covered in great detail, with some of the best coverage of policies I have seen. Many of the chapters in the second part of the book (and especially the seventh chapter) mention policies, and so this chapter lays the foundation for the book. The second chapter considers programming techniques using templates, giving a good idea of the way templates are applied and used.

Chapter 3 considers typelists. A typelist is a tool for manipulating a collection of datatypes. The abstract factory design pattern is discussed with regard to typelists. Allocating memory for small objects is the subject of the fourth chapter. This chapter fills a definite need, as there is a dearth of material on small-object allocators. Smart pointers and functors use small-object allocators, so this chapter also provides a foundation for other chapters in the book.

Part 2 begins with chapter 5, which deals with functors. Functors serve the role of a function, but behave as objects [2]. The author considers generalized functors, as described by the “command” design pattern, in this chapter. A singleton is a class that is instantiated only once. Implementing singletons is the subject of chapter 6. The author discusses issues such as singleton construction and destruction, dead references where reference counting is used with regard to singletons, singletons and multi-threading, the double-checked locking pattern, and de composing a singleton into policies.

Probably the best coverage of smart pointers I have seen presented in a book is given in chapter 7. This chapter uses many of the techniques presented in the first part of the book. The author starts with an introduction to smart pointers, and then proceeds to consider smart pointer techniques, policies, and applications. Chapters 8, 9, and 10 describe the generic implementation of three design patterns: the object factory in the eighth chapter, the abstract factory in the ninth, and the visitor pattern in the tenth.

In the final chapter, the author boldly tackles the topic of multi-methods. Multi-methods are the use of types of multiple operands to invoke an operator or method dynamically at run-time. Multi-methods are not available in C++, but some symbolic programming languages do support them. The ground covered by James Coplien [2] on simulating multi-methods in C++ is built upon significantly by the author in chapter 11. Coplien’s work set a standard for all books on advanced C++, and many of the idioms and techniques covered by Coplien are considered in this book, with the use of templates.

This work is not aimed at the novice programmer, and would be best suited for someone at an intermediate or advanced level with C++. However, I recommend that intermediate programmers brush up on their template and generic programming skills before reading the book, as they will be thoroughly tested (chapters 7 and 8 of Murray [3] will provide a good foundation).

Although the book is populated with ample example code, pedagogic aids are unfortunately missing. Also, an appendix presenting a list of the classes in the author’s Loki library, together with a short description for each class, would have been very welcome. The Loki library, developed to some extent in the second part of the book, is described at length throughout the book. The library, named after the Norse god Loki, can be downloaded from the author’s Web site (http://www.moderncppdesign.com), which also contains errata for the book.

Reviewer:  Nayan Ruparelia Review #: CR127090 (0306-0505)
1) Gamma, E.; Helm, R.; Johnson, R.; Vlissides, J. Design patterns: elements of reusable object-oriented software. Addison-Wesley, Boston, MA, 1995, See CR Rev. 9509-0650.
2) Coplien, J. O. Advanced C++ programming styles and idioms. Addison-Wesley, Boston, MA, 1992.
3) Murray, R. B. C++ strategies and tactics. Addison-Wesley, Boston, MA, 1993.
Bookmark and Share
 
C++ (D.3.2 ... )
 
 
Patterns (D.3.3 ... )
 
 
Software Libraries (D.2.2 ... )
 
 
Object-Oriented Programming (D.1.5 )
 
Would you recommend this review?
yes
no
Other reviews under "C++": Date
A C++ toolkit
Shapiro J., Prentice-Hall, Inc., Upper Saddle River, NJ, 1991. Type: Book (9780131276635)
Dec 1 1991
Borland C++ handbook
Pappas C., William H. I., McGraw-Hill, Inc., New York, NY, 1991. Type: Book (9780078810152)
Feb 1 1993
Going from C to C++
Traister R., Academic Press Prof., Inc., San Diego, CA, 1993. Type: Book (9780126974126)
Apr 1 1994
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy