Search⌘ K
AI Features

Template Method Example

Understand the template method pattern by examining a C++ example where a base class defines the algorithm structure and derived classes customize specific steps. Learn how to implement this pattern using a machine learning scenario with LinearRegression and Ann classes.

We'll cover the following...

Example

Let’s look at the code of the example we discussed in the previous lesson. We have a MlModel base class that defines a template method applyAlgo(). It has three steps:

  • readData()
  • writeData()
  • trainModel()

The first two are common to any machine learning model and are implemented in the base class itself. ...