Replies: 1 comment
-
Parser class is indeed getting too long and we should refactor it. Maybe set up as an issue for v2.0/v2.1? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Refactoring the
Parser
Class into Individual ParsersHello everyone,
I've been diving into our
Parser
class and realized that it's doing quite a lot. As our application grows and we handle more data types, it makes sense to split this class into more specialized parsers, like for activities, sleep, etc. Here's a proposal to refactor the current structure:1. Why Refactor?
Single Responsibility Principle: Each class should have one reason to change. This makes our codebase easier to understand and maintain.
Extensibility: With separate parsers, adding new data types or modifying existing ones becomes much more straightforward.
Testability: Smaller, specialized classes are generally easier to test, leading to more robust code.
2. Proposed Changes
a)
Parser
→SleepParser
+ActivityParser
+DietParser
SleepParser
This class will focus solely on parsing Sleep commands.ActivityParser
This class will focus solely on parsing Activity commands.DietParser
This class will focus solely on parsing Diet commands.3. Shared Logic
There's a good chance we have shared logic across parsers. We could:
Have a base class
BaseDataParser
that contains shared logic and methods.Utilize utility functions or shared helper methods where appropriate.
4. Adjustments to the Caller
Any part of our codebase that uses the current
Parser
will need adjustments. We need to identify these areas and make sure they call the appropriate parser.5. Tests
Refactoring also means adjusting our tests. Let's make sure:
Every parser has its own set of unit tests.
We maintain (or improve) our current test coverage.
Feedback
Do you see any potential pitfalls with this approach?
Are there other data types we should consider right now?
How do you feel about the base class vs. utility functions for shared logic?
Please share your thoughts, and let's make our codebase cleaner and more maintainable!
Beta Was this translation helpful? Give feedback.
All reactions