-
-
Notifications
You must be signed in to change notification settings - Fork 0
Added Factory Method #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the Factory Method design pattern in C++ and adds accompanying documentation.
- Introduces abstract and concrete
TransportandLogisticsclasses with a client service. - Demonstrates usage in
mainand provides a Markdown overview. - Adds
factory_method.hpp,factory_method.cpp, andindex.mdfor implementation and explanation.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| design_patterns/creational/factory_method/index.md | Added Markdown documentation outlining pattern concepts. |
| design_patterns/creational/factory_method/factory_method.hpp | Defined interfaces and concrete creator/product classes. |
| design_patterns/creational/factory_method/factory_method.cpp | Implemented main to showcase Factory Method usage. |
Comments suppressed due to low confidence (3)
design_patterns/creational/factory_method/factory_method.cpp:24
- [nitpick] Variable name
road_logistic_seris abbreviated and mixes naming styles; consider renaming toroadLogisticsServicefor clarity and consistency.
LogisticService road_logistic_ser(&roadLogistics);
design_patterns/creational/factory_method/factory_method.cpp:28
- [nitpick] Variable name
sea_logistic_seris abbreviated and mixes naming styles; consider renaming toseaLogisticsServicefor clarity and consistency.
LogisticService sea_logistic_ser(&seaLogistics);
design_patterns/creational/factory_method/index.md:1
- [nitpick] Consider adding a
Usage Examplesection with a small code snippet (e.g., instantiation and delivery calls) to make it easier for readers to see the pattern in action.
# 🏭 **Factory Method Design Pattern**
🎉 Snyk checks have passed. No issues have been found so far.✅ code/snyk check is complete. No issues have been found. (View Details) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Concrete Creator: RoadLogistics | ||
| class RoadLogistics : public Logistics { | ||
| public: | ||
| Transport* createTransport() const override { return new Truck(); } |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using raw new without corresponding cleanup creates potential memory leaks. Consider using smart pointers like std::unique_ptr<Transport> for automatic memory management, or ensure the caller is clearly responsible for deletion.
| // Concrete Creator: SeaLogistics | ||
| class SeaLogistics : public Logistics { | ||
| public: | ||
| Transport* createTransport() const override { return new Ship(); } |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using raw new without corresponding cleanup creates potential memory leaks. Consider using smart pointers like std::unique_ptr<Transport> for automatic memory management, or ensure the caller is clearly responsible for deletion.
| // Creator (Factory) Interface | ||
| class Logistics { | ||
| public: | ||
| virtual Transport* createTransport() const = 0; |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The factory method returns a raw pointer which requires manual memory management. Consider changing the return type to std::unique_ptr<Transport> to make ownership transfer explicit and prevent memory leaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|



This pull request introduces the Factory Method design pattern implementation in C++ along with documentation. The changes include the addition of
factory_method.cppandfactory_method.hppfiles to implement the pattern and anindex.mdfile to provide a detailed explanation of the pattern.Code Implementation:
design_patterns/creational/factory_method/factory_method.cpp: Implements the main function demonstrating the Factory Method pattern withRoadLogisticsandSeaLogisticsclasses.design_patterns/creational/factory_method/factory_method.hpp: Defines the Factory Method pattern with classes such asLogistics,RoadLogistics,SeaLogistics, andTransport. Includes both abstract and concrete implementations for products and creators.Documentation:
design_patterns/creational/factory_method/index.md: Provides a comprehensive overview of the Factory Method design pattern, including its key concepts, benefits, drawbacks, and use cases.