Other software patterns

As we mentioned, there is a total of 23 patterns linked to the original publication of the GoF group, but later on, other patterns belonging to the three main categories have appeared. Even a new category was defined: Concurrency patterns.

Among the three base categories, the additions are as follows:

  • Creational: The following are the sub types of this category:
    • Multiton: Focalizes the creation of classes through a single, global point and ensures that instances are only named instances.
    • Object Pool: Provides a cached system to avoid the expensive acquisition (or release) of resources. It does this by recycling any object that is not being used. Many specialists consider it a generalization of the connection pool and thread pool patterns.
    • Resource Acquisition is Initialization: Wikipedia states that this ensures that resources are properly released by tying them to the lifespan of suitable objects.
  • Structural: The following are the sub types of this category:
    • Extension object: Allows the addition of a functionality to a given hierarchy without changing it.
    • Front controller: This one has to do with web application design. It's a way to unify entry points to handle requests in a single node.
    • Marker: This is an empty interface to provide a way to link metadata to a class.
    • Module: Wikipedia says that it's intended to group several related elements, such as classes, singletons, methods, globally used, into a single conceptual entity.
    • Twin: A dangerous one; according to some specialists, this provides the modeling of multiple inheritance for languages that don't support this feature.
  • Behavioral: The following are the sub types of this category:
    • Blackboard: This is a pattern for artificial intelligence systems that allow the merging of different data sources (refer to https://en.wikipedia.org/wiki/Blackboard_system).
    • Null object: This is intended to avoid null references by providing a default object. In C#, we've seen how it is implemented using different operators (such as Null Coalescence and Null-Conditional Operators, which we saw in the initial chapters).
    • Servant: This defines common operations for a set of classes.
    • Specification: Recombines business logic in a Boolean fashion. There is abundant documentation of the implementation of this pattern in C# and how it has improved along with new versions of the language (https://en.wikipedia.org/wiki/Specification_pattern).
  • Concurrency patterns: These are specifically designed to deal with multithreading scenarios. The following table is inspired by the actual documentation of this subject available on Wikipedia:

    Name

    Description

    Active object

    Decouples method execution from the method invocation that resides in its own thread of control. The goal is to introduce concurrency using asynchronous method invocation and a scheduler to handle requests.

    Balking

    Only executes an action on an object when the object is in a particular state.

    Binding properties

    Combines multiple observers to force properties in different objects to be synchronized or coordinated in some way.

    Block chain

    A decentralized way to store data and agree on the ways to process it in a Merkle tree, optionally using a digital signature for any individual contributions.

    Double-checked locking

    Reduces the overhead of acquiring a lock by first testing the locking criterion (the lock hint) in an unsafe manner; only if that succeeds does the actual locking logic proceed.

    Can be unsafe when implemented in some language/hardware combinations. It can, therefore, be considered an anti-pattern sometimes.

    Event-based asynchronous

    Addresses problems with the asynchronous pattern that occurs in multithreaded programs.

    Guarded suspension

    Manages operations that require both a lock to be acquired and a precondition to be satisfied before the operation can be executed.

    Join

    Provides a way to write concurrent, parallel, and distributed programs by passing messages. Compared to the use of threads and locks, this is a high-level programming model.

    Lock

    A thread puts a "lock" on a resource, preventing other threads from accessing or modifying it.

    Messaging Design Pattern (MDP)

    Allows the interchange of information (that is, messages) between components and applications.

    Monitor object

    An object whose methods are subject to mutual exclusion, thus preventing multiple objects from erroneously trying to use it at the same time.

    Reactor

    Provides an asynchronous interface to resources that must be handled synchronously.

    Read-write lock

    Allows concurrent read access to an object, but requires exclusive access for write operations.

    Scheduler

    Explicitly controls when threads may execute single-threaded code.

    Thread pool

    A number of threads are created to perform a number of tasks, which are usually organized in a queue. Typically, there are many more tasks than threads. Can be considered a special case of the object pool pattern.

    Thread-specific storage

    Static or "global" memory that is local to a thread.

Also, remember that often, there's no need to explicitly implement a pattern when the framework you use already supports it (such as how it happens in the .NET Framework), and chances are that at the time of implementing a real solution, not one but several of these patterns might be required in order to code things properly.

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

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