Skip to content

Conversation

@c-dilks
Copy link
Member

@c-dilks c-dilks commented Jan 27, 2026

Adopt the Non-Virtual Interface (NVI) idiom for algorithms' Start, Run, and Stop functions.

Before this PR

Base-class Algorithm has 3 pure virtual functions:

// Algorithm.h
class Algorithm {
  public:
    virtual void Start(hipo::banklist& banks) = 0;
    virtual bool Run(hipo::banklist& banks) const = 0;
    virtual void Stop() = 0;
};

Subclass algorithms (i.e., the algorithms themselves) must override and implement:

// Algorithm.h
class AlgorithmClassName : public Algorithm {
  public:
    void Start(hipo::banklist& banks) override;
    bool Run(hipo::banklist& banks) const override;
    void Stop() override;
};
// Algorithm.cc
void AlgorithmClassName::Start(hipo::banklist& banks) { /*code*/ }
bool AlgorithmClassName::Run(hipo::banklist& banks) const { /*code*/ }
void AlgorithmClassName::Stop() { /*code*/ }

After this PR

  • Base-class Algorithm functions Start, Run, and Stop are now final, so they cannot be overridden; they are meant to stay public for the user and should not be changed by subclasses
  • Added private virtual functions, called "hooks", which may be overridden by subclass algorithms; they are called by the public functions
// Algorithm.h
class Algorithm {
  public:
    virtual void Start(hipo::banklist& banks) final;
    virtual bool Run(hipo::banklist& banks) const final;
    virtual void Stop() final;
  private:
    virtual void ConfigHook();
    virtual void StartHook(hipo::banklist& banks);
    virtual bool RunHook(hipo::banklist& banks) const;
    virtual void StopHook();
};

The implementations of the public functions are in the base-class's Algorithm.cc, and they call new private hook functions; basically:

// Algorithm.cc
void Algorithm::Start(hipo::banklist& banks)
{
  ConfigHook();
  StartHook(banks);
}
bool Algorithm::Run(hipo::banklist& banks) const
{
  return RunHook(banks);
}
void Algorithm::Stop()
{
  StopHook();
}

Required changes in Algorithms

In subclass algorithms (i.e., the algorithms themselves), 2 changes are required:

  1. In Algorithm.h
    • replace the public override function declarations of Start, Run, and Stop with private declarations of the hook functions that will be used
      • only declare the hooks that are actually used
      • make sure they are private
  2. In Algorithm.cc:
    • Move configuration parameter loading stuff (in Start) to ConfigHook
      • this is just to keep things cleaner
      • remove ParseYAMLConfig calls
    • Rename Start -> StartHook
    • Rename Run -> RunHook
    • Rename Stop -> StopHook (or just remove it entirely if it's not used)

Analogous changes are required in validators.

See this PR's diff for examples of the required changes, since this PR updates all existing algorithms and validators.

Purpose

Moving to the NVI pattern lets us:

@c-dilks c-dilks marked this pull request as ready for review January 27, 2026 23:27
@c-dilks c-dilks merged commit b6dfbfc into main Jan 28, 2026
19 checks passed
@c-dilks c-dilks deleted the nvi branch January 28, 2026 21:22
@github-project-automation github-project-automation bot moved this from Unsorted to Done in Iguana Jan 28, 2026
@c-dilks c-dilks added the technical PR that is a technical change (i.e., not important to prioritize in release notes) label Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

technical PR that is a technical change (i.e., not important to prioritize in release notes)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

setting log level from custom YAML file will not work for algorithms with no configuration

2 participants