Software Design Patterns

Software Design Patterns in Software Engineering

Software Design Patterns

Design = Solutions

  • Each of us has encountered a design problem and silently thought: I wonder if anyone has developed a solution to for this?

–What if there was a standard way of describing a problem (so you could look it up), and an organized method for representing the solution to the problem?

  • Design is about finding solutions
  • Unfortunately, designers often reinvent

–Hard to know how things were done before

Why things were done a certain way

–How to reuse solutions

How Experienced Designers Solve a Problem

  • Expert designers usually do not solve every problem from first principles, they reuse solutions that have worked for them in the past.
  • When they find a good solution, they use it again and again.
  • Such experience is part of what makes them experts.
  • Such kind of experiences can be recorded as design patterns

Design Pattern

  • Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over

(Christopher Alexander, A Pattern Language, 1977)

(Context: City Planning and Building architectures)

  • Design patterns represent solutions to problems that arise when developing software within a particular context.
  • Describes the context of usage
  • Design patterns are a codified method for describing problems and their solution allows the software engineering community to capture design knowledge in a way that enables it to be reused.

Design Pattern

  • Patterns capture the static and dynamic structure and collaboration among key participants in software designs
  • Patterns facilitate reuse of successful software architectures and designs
  • Design Pattern are descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.
  • Graphical notation is generally not sufficient
  • The history of the why, when, and how set the stage for the context of usage

What to Expect from Design Patterns?

  • A common design vocabulary
  • A documentation and learning aid
  • An adjunct to existing methods
  • A target for refining existing design

Design Patterns Goals

  • Codify good design

–Aid to novices and experts alike

–Abstract how to think about design

  • Give design structures explicit names

–Common vocabulary

–Reduced complexity

–Greater expressiveness

  • Capture and preserve design information

–Improve documentation

  • Facilitate restructuring/refactoring

–Additional flexibility

Design Pattern Catalogues

  • GoF (“the gang of four”) catalogue
  • POSA catalogue

–Pattern-Oriented Software Architecture

Effective Patterns

  • It solves a problem: Patterns capture solutions
  • It is a proven concept: Patterns capture solutions with a track record, not theories.
  • The solution isn’t obvious: Many problem-solving techniques (such as software design paradigms or methods) try to derive solutions from first principles. The best patterns generate a solution to a problem indirectly–a necessary approach for the most difficult problems of design.
  • It describes a relationship: Patterns don’t just describe modules, but describe deeper system structures and mechanisms.
  • The pattern has a significant human component (minimize human intervention). All software serves human comfort or quality of life

Kinds of Patterns

  • Architectural patterns : describe broad-based design problems that are solved using a structural approach.
  • Data patterns : describe recurring data-oriented problems and the data modeling solutions that can be used to solve them.
  • Component patterns : address problems associated with the development of components, the manner in which they communicate with one another, and their placement within a larger architecture
  • Interface design patterns : describe common user interface problems and their solution with a system of forces that includes the specific characteristics of end-users
  • WebApp patterns address a problem set that is encountered when building WebApps

Kinds of Patterns

  • Creational patterns : focus on the creation, composition, and representation of objects, e.g. Abstract factory pattern , Factory method pattern
  • Structural patterns focus on problems and solutions associated with how classes and objects are organized and integrated to build a larger structure
  • Behavioral patterns address problems associated with the assignment of responsibility between objects and the manner in which communication is effected between objects

Frameworks

  • Patterns themselves may not be sufficient to develop a complete design.
  • In some cases it may be necessary to provide an implementation-specific skeletal infrastructure, called a framework, for design work.
  • Selecting a reusable mini-architecture that provides the generic structure and behavior for a family of software abstractions, along with a context which specifies their collaboration and use within a given domain.
  • A framework is not an architectural pattern, but rather a skeleton with a collection of “plug points” that enable it to be adapted to a specific problem domain.
  • The plug points enable you to integrate problem specific classes or functionality within the skeleton.

Elements of Design Patterns

  • Design patterns have four essential elements:

–Pattern name

–Problem

–Solution

–Consequences

  • Pattern Name

–A handle used to describe a design problem, its solutions and its consequences

–Increases design vocabulary

–Enhances communication

–“The Hardest part of programming is coming up with good variable [function, and type] names.”

Elements of Design Patterns

  • Problem

–Describes when to apply the pattern

–Explains the problem and its context

–May describe specific design problems and/or object structures

–May contain a list of preconditions that must be met before it makes sense to apply the pattern

  • Solution

–Describes the elements that make up the design, relationships , responsibilities and Collaborations

–Does not describe specific concrete implementation

–Abstract description of design problems and how the pattern solves it

Elements of Design Patterns Solution

  • Consequences

–Results

–Critical for evaluating design alternatives, understanding costs , understanding benefits of applying the pattern

–Includes the impacts of a pattern on a system’s  flexibility ,extensibility ,portability

Design Pattern Descriptions

  • Name and Classification: Essence of pattern
  • Intent: What it does, its context
  • Motivation: Scenario illustrates a design problem
  • Applicability: Situations where pattern can be applied
  • Structure: Class and interaction diagrams
  • Participants: Objects/classes and their responsibilities
  • Collaborations: How participants collaborate
  • Consequences: results
  • Implementation: hints, techniques, etc.
  • Known Uses: Examples of pattern in real systems
  • Related Patterns: Closely related patterns
  • Sample Code

Novelists uses Patterns

  • Novelists and playwrights rarely design their plots from scratch.

Breadcrumbs

Description :

      On each page in a hierarchy, show a map of all the parent pages, up to the main page

Context :

The application or site has a straightforward tree structure, without much interlinking among the tree elements. Users work their way up and down this tree, either via direct navigation or searching.

Solution :

Near the top of the page, put a line of text or icons indicating the current level of hierarchy.

Structured Format

  • Description: Your interface requests a specific kind of text input from the user, formatted in a certain way.
  • Context: The input format expected by your program is familiar and well-defined, and your program don’t expect any users to need to deviate from the format you expect. Examples include credit card information, local telephone numbers, and license strings or numbers
  • Solution

–Design a set of text fields that reflect the format being asked for.

–Keep the text fields short, as clues to the length of the input.

–Once the user has typed all the digits or characters in the first text field, confirm it for her by automatically moving the input focus to the next field.

–She can still go back and re-edit the first one, of course, but now she knows how many digits are required there.

Game Patterns

  • Game elements
  • Resource and resource management
  • Information, communication and presentation
  • Actions and event patterns
  • Social interaction
  • Goals
  • Game Sessions

Game Patterns

Using the pattern :

  • Based on: time or turn, player actions, game events, element configuration etc.
  • Effects: what is produced, indicators to players, play mode changes etc.

High Score Lists

  • Description: give players the chance to rank themselves against other players who have previously played the game

Game Players use Patterns

  • Chess players, also relay on “patterns”

Power-Ups

  • Description: Power-Ups are game elements that give time-limited advantages to the player that picks them up

Pattern Organizing Table

Common Design Mistakes

  • Not enough time has been spent to understand the underlying problem, its context and forces, and as a consequence, you select a pattern that looks right, but is inappropriate for the solution required.
  • Once the wrong pattern is selected, you refuse to see your error and force fit the pattern.

Benefits of Design Patterns

  • Design patterns enable large-scale reuse of software architectures and also help document systems
  • Patterns explicitly capture expert knowledge and make it more widely available
  • Patterns help improve developer communication
  • Pattern names form a common vocabulary

Drawbacks to Design Patterns

  • Patterns do not lead to direct code reuse
  • Teams may suffer from pattern overload
  • Patterns are validated by experience and discussion rather than by automated testing
  • Integrating patterns into a software development process is a human-intensive activity.

Search within CuiTutorial

Scroll to Top