Repository navigation
refactor: use abstract factory pattern for card strategy instantiation - #56
Merged
Dejmenek merged 5 commits intoOct 27, 2025
Conversation
Updated `CardStrategyFactory` to implement the `ICardStrategyFactory` interface, providing methods to retrieve card strategies for individual cards and stacks. The constructor now accepts `ICardsRepository` and `IUserInteractionService` dependencies. Added `GetCardStrategyForStack` method for stack-based strategies. Created or updated `ICardStrategyFactory` interface to define method signatures, ensuring a consistent contract for obtaining card strategies.
Updated `CardsService` and `StacksService` to use a new `ICardStrategyFactory` dependency for dynamic card strategy creation. This refactor simplifies the strategy selection logic by utilizing factory methods, enhancing code maintainability. The `StacksService` constructor no longer requires an `ICardsRepository`, indicating a shift in responsibility for card strategy management.
Updated `Program.cs` to include a new using directive for `Flashcards.Services.CardStrategies` to improve organization and access to card strategy implementations. Added a new service registration for `ICardStrategyFactory`, allowing for dynamic creation of card strategies during runtime.
This commit introduces an `ICardStrategyFactory` dependency in both `CardsServiceTests.cs` and `StacksServiceTests.cs`. The factory is utilized to retrieve specific card strategies based on the card type, enhancing the flexibility of handling various card types such as Flashcards, Multiple Choice, and Cloze. Test methods in `CardsServiceTests.cs` and `StacksServiceTests.cs` have been updated to leverage the new factory, ensuring the correct strategy is returned during testing. Additionally, return values of mocked methods have been adjusted to align with the new strategy implementations, improving the accuracy of the tests.
Dejmenek
deleted the
51-refactor-card-strategy-instantiation-to-use-abstract-factory-pattern
branch
October 27, 2025 16:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces a
CardStrategyFactoryto instantiate different card strategies inCardsServiceandStacksService.Changes
CardStrategyFactory.cs: New class created to encapsulate card strategy creation logic.ICardStrategyFactory.cs: New interface defined for obtaining card strategies.CardsService.cs: Refactored to useICardStrategyFactoryfor strategy instantiation.StacksService.cs: Updated to utilizeICardStrategyFactoryfor managing card strategies.CardsServiceTests.csandStacksServiceTests.cs: Tests modified to use the new factory for obtaining card strategies