Skip to content

Instantly share code, notes, and snippets.

@atimin
Created September 20, 2020 19:35
Show Gist options
  • Save atimin/eb340014bd90aeda895a7d7621d3312b to your computer and use it in GitHub Desktop.
Save atimin/eb340014bd90aeda895a7d7621d3312b to your computer and use it in GitHub Desktop.
class ISmartObject {
 public:
  virtual int Foo() const = 0;
}
class RealObject : public ISmartObject {
 public:
  RealObject() { /* allocate resource and throw exception */ }
  int Foo() const override { /* do real work */ }
}
class MockObject : public ISmartObject {
 public:
  int Foo() const override { /* do nothing */ }
}
class ClientObject {
 public:
  ClientObject();
  UseSmartObject(const ISmartObject& obj); // Use interface not implementation!
}
// Somewhere in test
ClientObject obj;
obj.UseSmartObject(MockObject());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment