views:

138

answers:

9

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.

EDIT: I should make it clear that I'm looking for an answer that adheres to, ideally, one of the GoF design patterns, or some other well-established naming convention for things of this nature.

+5  A: 

To answer your literal question, I'd probably go with ConstructorFailure, as it describes the event of failing.

However, I'd probably go one step further and make it an Exception, in which case ConstructorException doesn't sound too shabby. Any reason you want to return this instead of throwing it?

Amadan
None of our code has exceptions enabled... >_>
Blair Holloway
+1  A: 

I'd go for DummyConstructor because its only purpose is to simulate a valid Constructor instance, but no real functionality is implemented by it.

Alexander Gessler
A: 

FailureResponseConstructor?

You're not creating a failure, you're creating the response to the failure. Thus, I would think any synonym to 'response' or 'respond' would work.

Jeffrey Kern
+2  A: 

Throw an exception. That is If I understand your description correctly and the creation of the IConstructor object is not done asynchronously.

Though if you don't have exceptions available to you I would probably call it ConstructorCreationError. Yes it does convey a failure mode but, more accurately, it is communicating the specific error that occurred. Also, having constructor as the last word, to me, seems to give the wrong meaning, but you could put "constructor" at the end as well.

You could also replace the verb "Creation" with something like SpawnConstructorError, ConstructorGenerationError and or if you're a fan of Dr. Chevalier maybe ErroneousConstructor.

joshperry
Correct, the creation of the `IConstructor` itself is synchronous. However, exceptions aren't available in this codebase, nor is the existing code designed to handle them. :(
Blair Holloway
I know how that is, working on a similar project... Updated with some naming suggestions.
joshperry
+1 for `ErroneousConstructor`. :)
Blair Holloway
A: 

If you willing to spend effort checking returned pointer against the "FailureConstructor", I don't see reason why couldn't you check it against NULL ?

Unless your system is designed to mask component failure from each other, it just doesn't make sense to assume every associated parts are working well.

YeenFei
The returning code would not check the pointer against `FailureConstructor`. Instead, it would check the returned result from `GetStatus()`, and determine a course of action from there. This is indeed the whole point of the `FailureConstructor` -- it is supposed to stand in for an actual constructor, which failed to materialize.
Blair Holloway
A: 

I'm going to go with something based on Niall C.'s comment -- FailedConstructorProxy. The Proxy pattern seems to fit best with what this class is; though rather than it relaying method calls to an object, it's standing in and generating what we wanted the actual constructor to return.

(If someone has a more correct answer, post it and I'll mark that one as accepted. I'm still not 100% convinced this is the right name!)

Blair Holloway
A: 

Why not create a Failed class to represent a class that failed construction and go with FailedConstructor? This way the naming is consistent.

Igor Zevaka
+3  A: 

I'd name it NullConstructor in line with the null object pattern, which is the pattern you're using. See http://en.wikipedia.org/wiki/Null_Object_pattern

Michael Anderson
Thinking about it, this seems most correct. It's constructing a NULL object.
Blair Holloway
A: 

FailedObjectConstructionHandler

this. __curious_geek