I want to write a python module so that other users can import and use. For simplicity, let's say that the module fetch data from a DB and return it to the user using a function which is the 'public' API of the module. But, there are different ways to fetch the data such as fetching the last line, or the first line, or 10 first lines from last week timestamp. In this function, one of the argument can define the way to fetch data, but I want to give the user the ability to create a new way of fetching that he can think of (and NOT by letting the user pass the SQL query as an argument).
What is the best approach to write such module? Is it by writing the module as a class that should be inherited by the user (Although I never inherit a module I import..)? Is it by using Enum for functions types and give some API to add types to it? Is it by overriding some in module functions?
Aucun commentaire:
Enregistrer un commentaire