Future Pattern


Problem


Some parts of the application require other parts, and may be as yet undefined. We need to test the existing part without writing the whole application.

Solution


Define a wrapper class to handle a message that has yet to come.

Related Patterns


  • Facade
  • Proxy
  • Adapter
  • Bridge

Discussion


The Future pattern is very useful for asynchronous operations, as well as during active development.

Examples


We could implement a database connection as a Future. That means we can use the shell interface until we are able to set up the database and connect that properly.

Code


Here, the implementation of Future can be changed in the future to reflect other parts of the system.

class Future{
  int toBeImplemented;
public:
  Future(int f){toBeImplemented = f;}
  int getval(){return toBeImplemented;}
}
int main(){
  Future f = new Future(3);
}