Skip to content

Instantly share code, notes, and snippets.

@rasheedamir
Last active March 18, 2016 16:46
Show Gist options
  • Save rasheedamir/cfe7fc29103f408e13e8 to your computer and use it in GitHub Desktop.
Save rasheedamir/cfe7fc29103f408e13e8 to your computer and use it in GitHub Desktop.
Design Patterns

Key patterns are organized into categories such as Caching, Exception Management, Logging and Instrumentation, Page Layout, Presentation, Request Processing, and Service Interface Layer; as listed below:

Exception Management - Exception Shielding: Filter exception data that should not be exposed to external systems or users.

Logging and Instrumentation - Provider: Implement a component that exposes an API that is different from the client API, to allow any custom implementation to be seamlessly plugged in.

Caching - Cache Dependency: Use external information to determine the state of data stored in a cache.

Caching - Page Cache: Improve the response time for dynamic Web pages that are accessed frequently but change less often and consume a large amount of system resources to construct.

Request Processing - Intercepting Filter: Create a chain of composable filters (independent modules) to implement common preprocessing and post processing tasks during a Web page request.

Request Processing - Page Controller: Accept input from the request and handle it for a specific page or action on a Web site.

Request Processing - Front Controller: Consolidate request handling by channeling all requests through a single handler object, which can be modified at run time with decorators.

Service Interface Layer - Façade: Implement a unified interface to a set of operations to provide a simplified, reduced coupling between systems.

Service Interface Layer - Service Interface: A programmatic interface that other systems can use to interact with the service.

Data Access - Active Record – Include a data access object within a domain entity.

Adapter – An object that supports a common interface and translates operations between the common interface and other objects that implement similar functionality with different interfaces.

Cache Dependency – Use external information to determine the state of data stored in a cache.

Capture Transaction Details – Create database objects, such as triggers and shadow tables, to record changes to all tables belonging to the transaction.

Data Mapper – Implement a mapping layer between objects and the database structure that is used to move data from one structure to another while keeping them independent.

Dependency Injection – Use a base class or interface to define a shared abstraction that can be used to inject object instances into components that interact with the shared abstraction interface.

Façade – Implement a unified interface to a set of operations to provide a simplified reduce coupling between systems.

Intercepting Filter - A chain of composable filters (independent modules) that implement common pre-processing and post-processing tasks during a Web page request.

Optimistic Offline Lock – Ensure that changes made by one session do not conflict with changes made by another session.

Page Cache – Improve the response time for dynamic Web pages that are accessed frequently, but change less often and consume a large amount of system resources to construct.

Pessimistic Offline Lock – Prevent conflicts by forcing a transaction to obtain a lock on data before using it.

Pipes and Filters - Route messages through pipes and filters that can modify or examine the message as it passes through the pipe.

Query Object – An object that represents a database query.

Repository – An in-memory representation of a data source that works with domain entities.

Row Data Gateway – An object that acts as a gateway to a single record in a data source.

Service Interface – A programmatic interface that other systems can use to interact with the service.

Table Data Gateway – An object that acts as a gateway to a table in a data source

Asynchronous Callback – Execute long running tasks on a separate thread that executes in the background, and provide a function for the thread to call back into when the task is complete.

Cache Dependency – Use external information to determine the state of data stored in a cache.

Chain of Responsibility – Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.

Composite View – Combine individual views into a composite representation.

Entity Translator – An object that transforms message data types into business types for requests, and reverses the transformation for responses.

Exception Shielding – Prevent a service from exposing information about its internal implementation when an exception occurs.

Front Controller – Consolidate request handling by channeling all requests through a single handler object, which can be modified at runtime with decorators.

Model View Controller – Separate the user interface code into three separate units; Model (data), View (interface), and Presenter (processing logic), with a focus on the View. Two variations on this pattern include Passive View and Supervising Controller, which define how the View interacts with the Model.

Page Cache – Improve the response time for dynamic Web pages that are accessed frequently, but change less often and consume a large amount of system resources to construct.

Page Controller – Accept input from the request and handle it for a specific page or action on a Web site.

Passive View – Reduce the view to the absolute minimum by allowing the controller to process user input and maintain the responsibility for updating the view.

Presentation Model – Move all view logic and state out of the view, and render the view through data-binding and templates.

Supervising Controller – A variation of the MVC pattern in which the controller handles complex logic, in particular coordinating between views, but the view is responsible for simple view-specific logic.

Template View – Implement a common template view, and derive or construct views using this template view.

Transform View – Transform the data passed to the presentation tier into HTML for display in the UI.

Two-Step View – Transform the model data into a logical presentation without any specific formatting, and then convert that logical presentation to add the actual formatting required.

Domain Model - is an object-oriented design pattern. The goal in a domain model design is to define business objects that represent real world entities within the business domain. When using a domain model design, the business or domain entities contain both behavior and structure. In other words, business rules and relationships are encapsulated within the domain model. The domain model design requires in-depth analysis of the business domain and typically does not map to the relational models used by most databases. Consider using the domain model design if you have complex business rules that relate to the business domain, you are designing a rich client and the domain model can be initialized and held in memory, or you are not working with a stateless business layer that requires initialization of the domain model with every request. For more information on the Domain Model and Domain-Driven Design, see the section "Domain-Driven Design" later in this chapter.

Table Module - is an object-oriented design pattern. The objective of a table module design is to define entities based on tables or views within a database. Operations used to access the database and populate the table module entities are usually encapsulated within the entity. However, you can also use data access components to perform database operations and populate table module entities. Consider using the table module approach if the tables or views within the database closely represent the business entities used by your application, or if your business logic and operations relate to a single table or view.

Factory - Create object instances without specifying the concrete type. Requires objects that implement a common interface or extend a common base class.

Transaction Script - Recommended for basic CRUD operations with minimal business rules. Transaction script components also initiate transactions, which means all operations performed by the component should represent an atomic unit of work. With this pattern, the business logic components interact with other business components and data components to complete the operation.

Adapter - Allow classes that have incompatible interfaces to work together, allowing developers to implement sets of polymorphic classes that provide alternative implementations for an existing class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment