jeudi 1 juillet 2021

Why hiding virtual functions behind non virtual equals [duplicate]

I have seen a pattern in code where you hide some of your virtual functions behind non virtual functions like this:

class IApa {
   public:
   virtual ~IApa() = default;

   void update() {
      doUpdate();
   };

   private:
   virtual void doUpdate() = 0;
};

class Apa: public IApa {
   private:

   void doUpdate() override {...}
};

I know that it is some kind of code pattern, but to me it only looks like you pollute the interface. What is the reason for using a pattern like this?

It is also possible that the examples I have seen is implemented wrong, do you know any design pattern that is similar to this, and what is the motivation for doing it?

Aucun commentaire:

Enregistrer un commentaire