OOP design pattern – calling super methods implicitly or some other solution

Is there a design pattern (probably but not necessarily OOP) whereby you can implicitly (not explicitly) call one function/method A form all the other methods in an object each time those other methods are called?

for example:

//pseudocode

class Foo {

int count = 0;

void countUp(){
count++;
}

 void doSomethingFirst(){
// call countUp implicitly here
}

void doSomethingSecond(){
// call countUp implicitly here
}
}

Would there be a way to use annotations in Java for instance? I could mark methods that need to call super methods or something. So it would be like an implicit call to super. I am not saying this is a great idea I am just wondering if it can be done somehow with a design pattern.


Source: oop

Leave a Reply