-
Notifications
You must be signed in to change notification settings - Fork 233
Description
Summary:
We propose implementing the Factory Design Pattern into the AI assistant to enable seamless support for multiple coding platforms (e.g., LeetCode, HackerRank). This approach will ensure that adding new platforms can be done with minimal changes to existing code, improving scalability and maintainability.
Current Approach:
The assistant requires the following data from the platform to assist the user:
- Problem name (for fetching chat history)
- Problem statement
- Programming language being used
- User's code
Proposed Solution:
We will create an abstract class Platform with methods to fetch the required information from different platforms. Each platform will implement this class, adapting the methods to fetch data from that specific platform’s HTML structure.
Code Example
Abstract Class: Platform
abstract class Platform {
abstract getProblemName(): string;
abstract getProblemStatement(): string;
abstract getProgrammingLanguage(): string;
abstract getUserCode(): string;
}Platform-Specific Subclasses:
Each platform will implement the abstract class and provide the specific logic for retrieving the required data from the HTML structure.
Note: the indexDB in using problem-name as primary-key to store chat history , so we can return the problemName
in the formate PlatformName-ProblemName to have uniqueness if multiple platforms have same problem name.
class LeetCodePlatform extends Platform {
getProblemName(): string {
return "LeetCode Problem Name"; // Example
}
getProblemStatement(): string {
return "LeetCode Problem Statement"; // Example
}
getProgrammingLanguage(): string {
return "JavaScript"; // Example
}
getUserCode(): string {
return "User's LeetCode Code"; // Example
}
}Platform Factory Class:
The factory class determines the platform based on the URL and returns the appropriate subclass.
Use Case:
-
Adding New Platforms: New platforms can be supported by implementing a new subclass of Platform and updating the PlatformFactory to detect the new platform's URL. This ensures that the assistant remains easily extensible.
-
Error Debugging: Platform-specific issues are isolated in the respective subclass, simplifying debugging and maintenance.
-
Encourage new contributors: new contributors con contribute easily to the project to provide support to new platforms easily.