Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am writing a library in C++ (making use of many C++11 features) that (as far as I can tell) implements the promise pattern.

The library consists of a class that makes asynchronous network requests. When a user of this class invokes a method that issues a network request, an instance of another class (we'll call it the "promise class") is returned that provides methods for canceling the request.

Since this application uses the Qt framework, the promise class also emits signals when certain events happen, one of which is the successful completion of the request. Because the result of the network request is often included when the signal is emitted, I feel that this class implements the promise pattern.

According to the Wikipedia article:

"In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete."

* emphasis mine

Have I missed anything? Does my class indeed implement the promise pattern?

share|improve this question
3  
You mean, like std::promise<T>? –  DeadMG Feb 12 '13 at 20:00
    
Probably as in Futures and Promises as the wikipedia article he linked. –  Dave Hillier Feb 12 '13 at 20:03
    
@DeadMG: Well sort of... except this isn't a multithreaded application. –  Nathan Osman Feb 12 '13 at 20:11
add comment

1 Answer

I think you have implemented it. Design patterns necessarily have somewhat generous definitions, as they need to work in a variety of application contexts.

Note: If your particular context is a homework problem and you are gathering evidence to challenge an unfavorable grade, well, that's between your and your professor. :) Out in industry, clean, functional code carries a lot more weight than compliance with narrow pattern definitions.

share|improve this answer
    
Nope, not a homework problem. Actually, I wanted to use the word "promise" in the class name and wanted to make sure it was accurately labelled. –  Nathan Osman Feb 13 '13 at 2:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.