mardi 12 avril 2022

Design Pattern- Modelling

I have a library with an Interface called Contract it has a function called verify() this is an abstract method. The user of this library implements the interface and its own version of verify() method. The verify method in the implement class is called by the library internally.

I want to create my own version of this library. So that there are some basic validations already in place and the verify function also gets called by the library. How do I go about doing this? Something I'm fiddling with below.

Class NewContract implements Contract{ 
bool verify() {
// basic validation rules
return newVerify();
}; 

abstract bool newVerify(); // this part to be implemented by the users.
}

Is there a better way to accomplish this? Because the library uses reflection and will load the class that implements Contract i.e. my implemented version = NewContract and not the class that the user will implement.

Aucun commentaire:

Enregistrer un commentaire