Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Use the Template Design Pattern to Customize a Base Class Service in a Derived Class

virtual member functions are widely used in object-oriented design but they don't always give you the flexibility you're after. For example, they don't let a derived class modify certain steps of a base class function while still retaining the original structure of the base class function. Learn how the Template design pattern solves this problem neatly.

n classic object-oriented design, a base class defines an interface in the form of public virtual member functions. A derived class may either override these functions or use them as-is. Often, this "all or nothing" policy is too coarse. What you really need is a more flexible design that allows a subclass to customize the functionality of a base class's service without overriding it entirely. This article shows how to use the Template design pattern to achieve such flexibility.

How can a subclass redefine certain steps of an algorithm without changing the algorithm's structure?

Use the Template design pattern.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date