I am developing a parser library where i parse data and store it in different data structures. The design of the library is such that it will have a DataProvider, Parser and DataStore class. The DataStore is a memebr of DataProvider class. The consumer needs to call the functions in the DataProvider to parse the file and to retrieve the data from the library.
Now if i expose the DataProvider class then i need to expose the DataStore class also which gives the implementation details to the consumer. What is the alternative way of exposing the functions of the DataProvider class? Should i expose functions like LoadFile, GetRecords and create the DataProvider object globally inside the cpp?
If the user doesn’t have to use the
DataStoredirectly, it should better not be exposed. You can achieve that by creating an “interface” – abstractDataProviderwith only public pure virtual functions. Internally, have aDataProviderImpwhich will inherit fromDataProvider, and contain all the required definitions and members that are part of the actual implementation.Let the user work only with the abstract class. This way, you drag only the minimal dependencies into your API.