Junior — Senior
Architecture extension: support for sources beyond files
livecode
Task condition
In the current system, two abstract interfaces are defined — IConnection and IFile. They allow working with file resources, but they can also be used to access other types of storage. Consider what new class should be added to this hierarchy to extend capabilities without modifying existing code.
Determine which additional data sources (for example, databases, network streams, cloud storage) would logically be connected by implementing the same interfaces IConnection and IFile. Such a solution will demonstrate how flexible the architecture is and how easily it can be adapted to new requirements.
class IConnection {
public:
virtual void connect(std::string) = 0;
virtual void disconnect() = 0;
virtual ~IConnection() {}
};
class IFile {
public:
virtual std::vector<std::string> Read() = 0;
virtual void Write(std::vector<std::string>) = 0;
virtual ~IFile() {}
};
class OurFile : public IConnection, public IFile {
void connect(std::string);
void disconnect();
std::vector<std::string> Read();
void Write(std::vector<std::string>);
};