I am writing a library in C++ (making use of many C++11 features) that (as far a
ID: 654281 • Letter: I
Question
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?
Explanation / 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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.