What do I name this class whose sole purpose is to report failure?
Posted
by Blair Holloway
on Stack Overflow
See other posts from Stack Overflow
or by Blair Holloway
Published on 2010-06-03T00:32:22Z
Indexed on
2010/06/03
0:34 UTC
Read the original article
Hit count: 326
In our system, we have a number of classes whose construction must happen asynchronously. We wrap the construction process in another class that derives from an IConstructor
class:
class IConstructor {
public:
virtual void Update() = 0;
virtual Status GetStatus() = 0;
virtual int GetLastError() = 0;
};
There's an issue with the design of the current system - the functions that create the IConstructor
-derived classes are often doing additional work which can also fail. At that point, instead of getting a constructor which can be queried for an error, a NULL
pointer is returned.
Restructuring the code to avoid this is possible, but time-consuming. In the meantime, I decided to create a constructor class which we create and return in case of error, instead of a NULL
pointer:
class FailedConstructor : public IConstructor
public:
virtual void Update() {}
virtual Status GetStatus() { return STATUS_ERROR; }
virtual int GetLastError() { return m_errorCode; }
private: int m_errorCode;
};
All of the above this the setup for a mundane question: what do I name the FailedConstructor
class? In our current system, FailedConstructor
would indicate "a class which constructs an instance of Failed
", not "a class which represents a failed attempt to construct another class".
I feel like it should be named for one of the design patterns, like Proxy
or Adapter
, but I'm not sure which.
© Stack Overflow or respective owner