Software Design Patterns Curtsy: Fahad Hassan (TxLabs)

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
Design Patterns Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
DESIGN PATTERNS Redesigning Applications And
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
(c) 2010 University of California, Irvine – André van der Hoek1July 16, 2015 – 13:45:31 Informatics 122 Software Design II Lecture 8 Nick Lopez Duplication.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
Design Patterns.
Software Waterfall Life Cycle Requirements Construction Design Testing Delivery and Installation Operations and Maintenance Concept Exploration Prototype.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Computing IV Singleton Pattern Xinwen Fu.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
Creational Patterns
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Stephenson College DP 98 1 Design Patterns by Derek Peacock.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns Spring 2017.
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
How to be a Good Developer
Design Patterns with C# (and Food!)
object oriented Principles of software design
How to be a Good Developer
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Informatics 122 Software Design II
Chapter 8, DesignPatterns Facade
Presentation transcript:

Software Design Patterns Curtsy: Fahad Hassan (TxLabs)

Outline Software Design Principles What are Design Patterns? Types of Design Patterns Details on the Design Patterns

What are Software Design Principles? Software design principles represent a set of guidelines that helps us to avoid having a bad design. The design principles are associated to Robert Martin who gathered them in "Agile Software Development: Principles, Patterns, and Practices".

Characteristics of a Bad Design According to Robert Martin there are 3 important characteristics of a bad design that should be avoided: Rigidity - It is hard to change because every change affects too many other parts of the system. Fragility - When you make a change, unexpected parts of the system break. Immobility - It is hard to reuse in another application because it cannot be separated out from the current application.

Open Close Principle Software entities like classes, modules and functions should be open for extension but closed for modifications.

Dependency Inversion Principle High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.

Interface Segregation Principle This principle teaches us to take care how we write our interfaces. Clients should not be forced to depend upon interfaces that they don't use. For example if we create an interface called Worker and add a method lunch break, all the workers will have to implement it. What if the worker is a robot?

Single Responsibility Principle A class should have only one reason to change. When we need to make a change in a class having more responsibilities the change might affect the other functionality of the classes.

What are Design Patterns? Design patterns provide solutions to common software design problems. In the case of object-oriented programming, design patterns are generally aimed at solving the problems of object generation and interaction, rather than the larger scale problems of overall software architecture. They give generalized solutions in the form of templates that may be applied to real-world problems.

Three Types of Patterns Creational patterns: Creational patterns provide ways to instantiate single objects or groups of related objects. Structural patterns: Structural patterns provide a manner to define relationships between classes or objects. Behavioral patterns: Behavioral patterns define manners of communication between classes and objects.

Creational patterns The first type of design pattern is the creational pattern. Examples: Prototype. Singleton. Abstract Factory. Builder. Factory Method.

Singleton Design Pattern The singleton pattern ensures that only one object of a particular class is ever created. Ensures that a class can only have one concurrent instance. Whenever additional objects of a singleton class are required, the previously created, single instance is provided. All further references to objects of the singleton class refer to the same underlying instance. This is a creational pattern as it is used to control class instantiation.

Singleton Design Pattern (Cont.) An example of the use of a singleton class is a connector to a legacy data file that only supports a single reader at any time. In this case, creating multiple instances of the legacy data connector would simply cause all but the first to fail when reading from the file. By forcing a single, global instance to be used, only one underlying connection would ever be active.

Singleton Design Pattern (Cont.) The UML class diagram above describes an implementation of the singleton pattern. The constructor for the class is marked as private. This prevents any external classes from creating new instances. The class is also sealed to prevent inheritance, which could lead to subclassing that breaks the singleton rules.

Singleton Design Pattern (Cont.)

_lockThis Why have we used _lockThis? By locking the dummy "_lockThis" variable whilst checking, and possibly creating, the instance variable, all other threads will be blocked for very brief period. This means that no two threads will ever be able to simultaneously create their own copies of the object.

Prototype Design Pattern The prototype design pattern is a design pattern that is used to instantiate a class by copying, or cloning, the properties of an existing object. The new object is an exact copy of the prototype but permits modification without altering the original. This is a creational pattern as it is used to control class instantiation and object generation. We can do shallow copy as well as deep copy.

Shallow Copy

Deep copy

Prototype Design Pattern (Cont.) The pattern is used to instantiate a new object by copying all of the properties of an existing object, creating an independent clone.

Prototype Design Pattern (Cont.) The UML class diagram above describes an implementation of the prototype pattern: Prototype: This abstract class is the base class for the types of object that can be generated and cloned. ConcretePrototype (A/B): These classes inherit from the Prototype class and include any additional required functionality.

Prototype Design Pattern (Cont.)

Structural Patterns The second type of design pattern is the structural pattern. Structural patterns provide a manner to define relationships between classes or objects. Examples: Adapter. Composite. Decorator. Facade. Flyweight. Proxy.

Adapter Design Pattern The adapter pattern is a design pattern that is used to allow two incompatible types to communicate. Where one class relies upon a specific interface that is not implemented by another class, the adapter acts as a translator between the two types. This is a structural pattern as it defines a manner for creating relationships between classes.

Adapter Design Pattern (Cont.)

Facade Design Pattern The facade pattern is a design pattern that is used to simplify access to functionality in complex or poorly designed subsystems. The facade class provides a simple, single-class interface that hides the implementation details of the underlying code. The facade pattern is ideal when working with a large number of interdependent classes, or with classes that require the use of multiple methods, particularly when they are complicated to use or difficult to understand.

Facade Design Pattern (Cont.)

Behavioral Patterns The final type of design pattern is the behavioral pattern. Behavioral patterns define manners of communication between classes and objects. Examples: Chain of Responsibility. Command. Interpreter. Iterator. Mediator. Memento. State. Strategy. Template Method. Visitor.

Template Method Design Pattern (Cont.) The template method pattern is a design pattern that allows a group of interchangeable, similarly structured, multi-step algorithms to be defined. Each algorithm follows the same series of actions but provides a different implementation of the steps. The overall structure of the basic algorithm is defined in an abstract base class.

Template Method Design Pattern (Cont.)

Observer Design Pattern

That’s all folks!