#include <string> #include <iostream> #include <thread> using namespace std; // The function we want to execute on the new thread. void task1(string msg) { cout << “task1 says: ” << msg; } int main() { // Constructs the new thread and runs it. Does not block execution. thread t1(task1, “Hello”);Continue Reading

The observer(subject) is an object that maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.   Example – Python: class Observable: def __init__(self): self.__observers = [] def register_observer(self, observer): self.__observers.append(observer) def notify_observers(self, *args, **kwargs): for observerContinue Reading

The decorator pattern allows behavior to be added to an individual object. Example c#   public abstract class BaseSalad { protected double myPrice; public virtual double GetPrice() { return this.myPrice; } } public abstract class ExtrasDecorator : BaseSalad { protected BaseSalad salad; public ExtrasDecorator(BaseSalad saladToDecorate) { this.salad = saladToDecorate; }Continue Reading