The Dynamic Template Pattern

Fernando Lyardet · 1997

Motivation As an introduction consider the videotape example presented for the Type Object [Woolf 96]. Since many of the videotapes are very similar, the videotape’s instance share a lot of redundant information. Following this example, all copies of Star Wars would be similar: they have the same title, rental price, and other data. Thus, the repetition of that information throughout all copies of Star Wars would be redundant. There are many ways to overcome this problem. One approach is to subclass VideoTape for each movie. Each time a movie is added to the system, it would be necessary to add a new subclass and recompile the system. This approach is neither practical nor flexible. They key problem is how to deal with the fact that each type of videotape needs to be an instance of a class of type videotape. As expressed in Woolf[96], the key step is to implement two classes, one of whose instances represents application instances and the other one whose instances represents what would normally be the application classes. Each application instance has a pointer to its corresponding class-instance. So, to implement this solution two classes should be involved: one to represent the VideoTape and other to represent the Movie.

Read the paper · More papers on PaperTik