Skip to main content
12 events
when toggle format what by license comment
Jan 12, 2022 at 5:54 comment added sattva_venu How does mocking works with this factory code?
Mar 7, 2021 at 19:16 comment added silence_lamb I feel this answer is not complete. What are the next steps after creating a factory? Why creating a factory will solve the problem?
S Jan 13, 2017 at 3:13 history suggested Quentin CC BY-SA 3.0
Added missing function call to the example
Jan 11, 2017 at 14:15 review Suggested edits
S Jan 13, 2017 at 3:13
Jan 20, 2014 at 13:17 vote accept dotbugfix
Jan 16, 2014 at 15:05 comment added BЈовић @James Yes, it would work as well.
Jan 16, 2014 at 14:08 comment added James unique_ptr does that too
Jan 16, 2014 at 14:02 comment added BЈовић @James I assumed that CAnotherClassInterface (interface of CAnotherClass class) is an abstract class, and I assumed that the created object is destroyed at the end of the foo function.
Jan 16, 2014 at 13:45 comment added James Why is shared_ptr required here?
Jan 16, 2014 at 12:21 comment added BЈовић @dotbugfix You can do that with macros as well. I am not sure what you mean with "that would make the overall design too specific". Every design is specific for certain set of requirements. With the use of dependency injection, you break the coupling in a very nice way - and that is good.
Jan 16, 2014 at 10:40 comment added dotbugfix Most of the times the object creation is already using a factory. Do you think this could be leveraged by making sure the factory returns a mock instead of an actual in case of a unit test environment. I'm looking at pre-processor "flags" and #ifdefs in the factory method while compiling for test. Isn't this a too custom-made approach? Writing #ifdefs in just the factories seems much better than mingling with actual code (like dependency injection); but that would make the overall design too specific, wouldn't it?
Jan 16, 2014 at 10:26 history answered BЈовић CC BY-SA 3.0