I know there can't exist a 'semi-virtual' method, however, I've run into a design related issue.
Let's say I have a base class called WebPage. This class has a method called UpdatePage(). But because this method exists within an abstract WebPage object, the UpdatePage() method is virtual, and should be implemented by a user who is deriving a concrete class from WebPage.
But let's say that when the UpdatePage() method is called, it would be ideal that it timestamps some class data member regarding the last update time.
I'm in a position where I want some default implementation from a method (i.e. do a timestamp), but I also want the implementation to be custom to the concrete class derived from the base class WebPage.
I know I could come up with some technique to solve this issue. For example, I could make UpdatePage() non-virtual, and have it contain two methods: a timeStamp() method which is non-virtual, and a updateImplementation() method which is pure-virtual. This way when a user calls UpdatePage(), there would exist default and custom behavior.
But again, if there exists some design pattern/rule for this, I'd like to not reinvent the wheel.
Thanks!
Aucun commentaire:
Enregistrer un commentaire