Skip to content

Conversation

@gvatsal60
Copy link
Owner

This pull request introduces the Factory Method design pattern implementation in C++ along with documentation. The changes include the addition of factory_method.cpp and factory_method.hpp files to implement the pattern and an index.md file to provide a detailed explanation of the pattern.

Code Implementation:

Documentation:

@gvatsal60 gvatsal60 self-assigned this Jun 23, 2025
Copilot AI review requested due to automatic review settings June 23, 2025 12:27
@gvatsal60 gvatsal60 added the documentation Improvements or additions to documentation label Jun 23, 2025
@gvatsal60 gvatsal60 added the enhancement New feature or request label Jun 23, 2025
@gvatsal60 gvatsal60 enabled auto-merge June 23, 2025 12:27
Copy link
Contributor

Copilot AI left a 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 Transport and Logistics classes with a client service.
  • Demonstrates usage in main and provides a Markdown overview.
  • Adds factory_method.hpp, factory_method.cpp, and index.md for 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_ser is abbreviated and mixes naming styles; consider renaming to roadLogisticsService for clarity and consistency.
  LogisticService road_logistic_ser(&roadLogistics);

design_patterns/creational/factory_method/factory_method.cpp:28

  • [nitpick] Variable name sea_logistic_ser is abbreviated and mixes naming styles; consider renaming to seaLogisticsService for clarity and consistency.
  LogisticService sea_logistic_ser(&seaLogistics);

design_patterns/creational/factory_method/index.md:1

  • [nitpick] Consider adding a Usage Example section 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**

@gvatsal60 gvatsal60 disabled auto-merge June 23, 2025 12:30
@gvatsal60
Copy link
Owner Author

🎉 Snyk checks have passed. No issues have been found so far.

code/snyk check is complete. No issues have been found. (View Details)

Copilot AI review requested due to automatic review settings September 29, 2025 03:31
Copy link
Contributor

Copilot AI left a 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(); }
Copy link

Copilot AI Sep 29, 2025

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.

Copilot uses AI. Check for mistakes.
// Concrete Creator: SeaLogistics
class SeaLogistics : public Logistics {
public:
Transport* createTransport() const override { return new Ship(); }
Copy link

Copilot AI Sep 29, 2025

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.

Copilot uses AI. Check for mistakes.
// Creator (Factory) Interface
class Logistics {
public:
virtual Transport* createTransport() const = 0;
Copy link

Copilot AI Sep 29, 2025

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.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings October 7, 2025 16:31
Copy link
Contributor

Copilot AI left a 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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants