I am new to python and I have to design a Python API(version - 2.7) similar to an existing Java API
Python version - 2.7
The Java API is as follows
public interface Process<T> {
Future<T> create(Client<T> client)
//Other methods
}
public interface Client<T> extends Serializable {
T execute(ClientContext c)
//Other methods
}
public interface ClientContext {
File createFile(String path)
//Other methods
}
The equivalent Python API design that I have come up with is
Approach1
class Process:
__metaclass__ = ABCMeta
@abstractmethod
def create(self, client):
pass
class Client:
__metaclass__ = ABCMeta
@abstractmethod
def execute(self, context):
pass
class ClientContext:
__metaclass__ = ABCMeta
@abstractmethod
def createFile(self, path):
pass
Approach2
Can I use closures to directly pass the context to the create function of Process class so that I can eliminate the Client class
Note The create method of Process class will process async tasks which can be done using concurrent.futures package from python.
I want to know which of the 2 approaches is good
Also open to better approaches as well
Aucun commentaire:
Enregistrer un commentaire