Temporal decoupling

This type of decoupling isn't talked about much because it only applies to a few situations and, most of the time, this isn't what we want. Usually, when we call a function we want it to execute immediately. We have a specific algorithm in our code and the timing and order of that code is very important. This isn't true of all code. One situation is multithreaded code, in which multiple paths of code are executing simultaneously. Other situations are UI or context sensitive buttons, where the action to be executed is set up in advance instead of hardcoded in place. Let's look at some code as an example:

//Examples of setting up function calls 
//Immediate execution
Add(5, 6);
//Delayed execution
Command* p1 = new TwoArgCommand(Add, 5, 6);

//Immediate execution
someObject.Display();
//Delayed execution
Command* p2 = new SomeObjectCommand(&object,&SomeObject::Display);

In all four of the above situations, the functions and parameters are given. However, the command versions can be passed to other methods, called and/or recalled based on the need of the client.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.29.119