Design Patterns 

In software engineering design pattern is defined as a “ description of a solution to a recurring problem between a context, proven by experience to lead to a superior result when properly applied”. A design pattern isn’t a finished design that can be transformed directly into code; it is a description for a template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. The algorithm is not thought of as design patterns since they solve computational problems rather than design problems.

 

Patterns are a way to document good, proven, general solutions to commonly recurring problems. These solutions may be applied within a specific context and serve to resolve various forces,  potential hazards that may cause problems later. Application of a pattern may have consequences good or bad as described by the pattern.

 

 

Users

Design patterns 10 speed up the development process by providing tested, proven development Paradigms. Effective software designing requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.

 

Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, document in a format that doesn’t require specifics tied to a particular problem.

 

 

Documentation

That documentation for a design pattern should contain enough information about the problem that the pattern addresses. the context in which it is used, and the subject and the suggested solution. Nonetheless, the authors use their own layouts to document design patterns, and these layouts usually resemble the essential parts. The authors usually include additional sections to provide more information and organize The essential parts in different sections, possibly with different names. 

 

The following is a layout which is used to document Design patterns:

  1. Pattern name and classification: Every pattern should have a descriptive and unique name that helps in identifying and referring to it. Additionally, the pattern should be classified according to a classification. This classification helps in identifying the use of the pattern.
  2. Problem or Intent: This section should describe the goal behind the pattern and the reason for using it. It resembles the problem part of the pattern.
  3. Motivation: This section provides a scenario consisting of a problem and a context in which this pattern can be used. By relating the problem and the context, this section shows when this pattern is used.
  4. Applicability: This section includes situations in which this pattern is usable. it represents the contact part of the pattern.
  5. Structure: A graphical representation of the pattern. Class diagrams and interaction diagrams can be used for this purpose.
  6. Forces or Consequences: Explain the issues surrounding the problem, how the solution resolves those issues and the potential benefits and trade-offs of applying the solution.
  7. Known Uses: Provides some descriptions of a few known situations that have successfully applied this solution.
  8. Also known as:  A pattern could have more than one name. These names are documented in this section.
  9. Related patterns:  This section includes other patterns that have some relation with this pattern, so that they can be used along with the pattern, or Instead of the pattern. It also includes the differences this pattern has with similar patterns.

 

Note:  Not all published patterns will contain all of these sections and some may have additional sections. However, all well-written software design patterns will have at least the first six sections and, preferably, all nine.

 

 

Classification

Design patterns can be classified in terms of the underlying problem they slove. The researchers collected 23 of the most commonly used general purpose design patterns that are application domain independent and classified them in three categories.

 

Example of problem-based pattern classifications as follows: 

 

Creational Patterns

This design pattern is all about class instantiation. Deals with the best way to create instances. Create an object at run time and not at compile time.

  1. The factory pattern -  it deals with the problem of creating objects products) without specifying the exact class of object that will be created.
  2. The abstract factory pattern -  provides a way to encapsulate a group of individual factories that have a common theme.
  3. The builder pattern -  is used to enable the creation of a variety of complex objects from one source object.
  4. The prototype pattern -  used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects.
  5. The singleton pattern -  is used to restrict instantiation of a class to one (or a few) objects.

 

Structural Patterns

Structural patterns describe how classes and objects can be combined to form large structures.

Structural patterns include: 

  1. Adaptor -  make things work after they are  designed
  2. Bridge  make things work before they are
  3. Composite is the composition of objects
  4. Decorator  provides an enhanced interface
  5. Facade  represents an entire subsystem
  6. Flyweight  is a pattern for sharing objects
  7. Proxy represents and other objects

 

Behavioral Patterns

Behavioral patterns are concerned with the assignment of the responsibilities between objects, or, in encapsulating behavior in an object and delegating the request to it.

Behavioral patterns include:

  1. Observe define the way a number of classes can be notified of a change.
  2. Mediator uses of class to simplify communication between other classes.
  3. Memento provides a way to capture an object’s state.
  4. Chain of responsibility allows a number of classes to attempt to handle a request.
  5. The template provides an abstract definition of an algorithm.
  6. The interpreter provides a definition of how to include language elements in the program.
  7. Strategy  encapsulates an algorithm inside the class
  8. A visitor adds functions to a class.
  9. State provides memory for a class’s instance variables.
  10. Command  encapsulates an action at an object.
  11. Iterator formalizes the way we move through a list of data.

 

Documentation of Patterns

Singleton

Pattern  name & Classification - Singleton creational pattern.

Problem or Intent - This is a creational design pattern which ensures that the class has only a single occurrence (instance)  and there is a global point of access to it.

 

Motivation

There are some situations where a class should have exactly one instance:

  • There can be only one president for our country
  • There can be only one printer spooler for the system through it can have many printers
  • There can be only one window manager for a system

 

Applicability 

The singleton pattern is used when:

  • There must be exactly one instance of a class
  • It must be accessible to clients from a well-known access point.
  • Sole instant should be extendable by subclassing, but clients should be able to use an extended class without modifying their codes.

 

Structure

 

Singleton

staticuniqueInstance

singletonData

static Instance()

SingletonOperation()

GetsingletonData

 

Benefits of Consequences

 

  • Controlled access to a single instance
  • Produced namespace by avoiding global variable
  • Permits refinement of operations through subclassing
  • Can be used to permit a variable number of instances rather than just one

About Tec News

Tec News is optimized for learning Web Development, Programming, Database System and Tutorials, Articles, References for your development. This web help developers, learners learn these technologies easy and free.

Contact Us

If you have any suggestions or have any questions regarding our web please feel free to contact us.

info@tec-news.com        

https://www.tec-news.com