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

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. ExampleContinue Reading