create_ipc_message
These objects are used often, but possibly for a short period of time
Webserver wants each request to run in its own thread, but don't want to create a thread each time. Solution: Create a thread pool
Idiom used in object-oriented, statically-typed languages.
Useful to make sure resources are released when an exception is thrown.
Mostly in C++
Adapter: adapt interface per a given set of expectations Aggregate: Composite with methods for aggregation of children Bridge: decouple an abstraction from its implementation so they can vary Composite: free structure of objects where every object has same interface Decorator: Add additional functional to an object Extensibility: Facade Flyweight Marker Pipes and filters Opaque pointer Proxy These all adapt interfaces
Have a single request handled by several different objects/levels/systems etc
Logger has 3 different possible loggers In calling code, instantiate logger and add the loggers with each their own log level When the logger is asked to a log a message, it will only call the loggers appropriate to the particular log level provided to the call
Works well with protocol stacks: send a message and it goes up or down the stack to the physical layer, and then goes back to the application layer
Object wrapping a function. You give that object to be executed by someone else
Class which has or is a container
Instead of iterating through each element of the container, you have an interface which returns an object with a next()
method which navigates to the subsequent element of that same container
Abstraction layer over a container
Used in user interfaces
Infamous Undo
and Redo
Memento has a state that can be stored. If you have a stack of memento, you can implement the logic to work through the stack of previous states
AKA Observer Pattern
How:
Like chain of responsibility, but rather than a request going to a bunch of different objects, instead it's something which happens while visiting a certain structure
Activeobject design pattern decouples method execution from method invocation for objects that reside in their own thread.
Command pattern is applied here.
Pattern consists of six elements:
See example in code
If two threads can change bank balance, you are in trouble. Lock access to account balance
Allows for locking of variable without a mutex Atomic operations cannot be interrupted by another thread Works with fundamental types (int, float) Made possible through Assembler call "Compare and Exchange" CMPXCHG Modern languages support this and take care of calling the right Assembler instruction Checks the value of a variable and then sets its value in a single operation without the possibility of being interrupted
static std::atomic_bool exiting(false);
if (exiting.exchange(true)) return;