SOLID DESIGN PATTERNS FOR MERE MORTALS

Similar documents
DESIGN PATTERNS FOR MERE MORTALS

Using Design Patterns in Java Application Development

VERSION ASP.NET CORE APIS

SDC Design patterns GoF

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Applying the Observer Design Pattern

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Object-Oriented Design

JAVASCRIPT FOR THE C# DEVELOPER

DESIGN PATTERN - INTERVIEW QUESTIONS

Design Patterns Reid Holmes

What is Design Patterns?

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

Object-Oriented Oriented Programming

Design patterns. Jef De Smedt Beta VZW

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Topics in Object-Oriented Design Patterns

Object-Oriented Design

Applying the Decorator Design Pattern

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Applying the Factory Method Design Pattern

Object-oriented Software Design Patterns

Design Patterns. An introduction

Design Patterns. Gunnar Gotshalks A4-1

Design Pattern and Software Architecture: IV. Design Pattern

1 Software Architecture

3 Product Management Anti-Patterns by Thomas Schranz

Software Design COSC 4353/6353 D R. R A J S I N G H

TEST DRIVEN DEVELOPMENT FOR T-SQL IT S NOT JUST TESTING FIRST!

Object Oriented Paradigm

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Tuesday, October 4. Announcements

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

Application Architectures, Design Patterns

Introduction to Testing and Maintainable code

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

What is Design Patterns?

Brief Note on Design Pattern

An Introduction to Patterns

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Software Design COSC 4353/6353 D R. R A J S I N G H

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

The GoF Design Patterns Reference

SECURING ASP.NET CORE APPLICATIONS

Design Patterns. (and anti-patterns)

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Introduction to Software Engineering: Object Design I Reuse & Patterns

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

IMPLEMENTING MODEL VIEW VIEW-MODEL IN WINJS

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

What is Design Patterns?

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

The Design Patterns Matrix From Analysis to Implementation

An Introduction to Patterns

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Summary of the course lectures

Software Development Project. Kazi Masudul Alam

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

CS342: Software Design. November 21, 2017

A Primer on Design Patterns

11/12/12. Objectives DESIGN PATTERNS. Design Pattern. Defined Design Patterns. Applying Design Patterns. Motivating Example

Design Pattern- Creational pattern 2015

Development and Implementation of Workshop Management System Application to Explore Combing Multiple Design Patterns

Dependency Inversion, Dependency Injection and Inversion of Control. Dependency Inversion Principle by Robert Martin of Agile Fame

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

Design patterns. OOD Lecture 6

Design Patterns: Structural and Behavioural

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Object Oriented Programming. Michał Bereta

Review Software Engineering October, 7, Adrian Iftene

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

A Reconnaissance on Design Patterns

Agile Architecture. The Why, the What and the How

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

Design Patterns #3. Reid Holmes. Material and some slide content from: - GoF Design Patterns Book - Head First Design Patterns

An Expert System for Design Patterns Recognition

2.1 Design Patterns and Architecture (continued)

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

2.1 Design Patterns and Architecture (continued)

25.1 Introduction Façade Design Pattern Identification Problem Structure Participants...

Advanced Object Oriented PHP

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Kerievsky_book.fm Page 355 Thursday, July 8, :12 PM. Index

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

Design Patterns. Hausi A. Müller University of Victoria. Software Architecture Course Spring 2000

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

VOL. 4, NO. 12, December 2014 ISSN ARPN Journal of Science and Technology All rights reserved.

Transcription:

SOLID DESIGN PATTERNS FOR MERE MORTALS Philip Japikse (@skimedic) skimedic@outlook.com www.skimedic.com/blog Microsoft MVP, ASPInsider, MCSD, MCDBA, CSM, PSM, PSD Consultant, Teacher, Writer

Phil.About() Consultant, Coach, Author, Teacher Lynda.com (http://bit.ly/skimediclyndacourses) Apress.com (http://bit.ly/apressbooks) Microsoft MVP, ASPInsider, MCSD, MCDBA, CSM, PSM, PSD Founder, Agile Conferences, Inc. http://www.dayofagile.org President, Cincinnati.NET User s Group

A LOOK AT SOLID

SINGLE RESPONSIBILITY PRINCIPLE Do one thing and do it well! http://joshlinkner.com/images/2012/05/san.jpg

OPEN CLOSED PRINCIPLE Be Open for Extension, Closed for Modification http://www.wellgolly.com/images/wwtt_house.jpg

LISKOV SUBSTITUTION PRINCIPLE Derived Classes Can Stand In for Base Classes http://beerimages.com/wp-content/uploads/2011/03/beer-collection.jpg

INTERFACE SEGREGATION PRINCIPLE Make Interfaces Fine Grained and Client Specific

DEPENDENCY INVERSION Depend On Abstractions, Not Concrete Implementations

ADDITIONAL CONSIDERATIONS

DON T REPEAT YOURSELF (DRY) Clip-board Inheritance is an anti-pattern!

THE BOY SCOUT PRINCIPLE Clean up after yourself Clean up after others

YAGNI You Ain t Gonna Need It http://www.k-photography.info/srvgdata-gold-plated-toilets.asp

SEPARATION OF CONCERNS Focusing one s attention upon some aspect Edsger Dijkstra https://sf.curbed.com/2017/3/10/14889950/kitchen-bathroom-sf-combined-toilet

DESIGN PATTERNS

MOTIVATION FOR DESIGN PATTERNS The goal is not to bend developers to the will of some specific patterns, but to get them to think about their work and what they are doing --Phil Haack

WHAT ARE DESIGN PATTERNS? General Reusable Solutions To A Common Problem Conceptual Defined by Purpose and Structure Method of Communication Support SOLID development NOT CODE!

TYPES OF DESIGN PATTERNS Creational Deal with instantiation of objects (Singleton, Factories, Prototype) Structural Deal with Composition and Relations (Adapter, Façade, Decorator) Behavioral Deal with responsibilities and communication between objects (Command, Strategy, Observer, Pub-Sub, Memento, Template Method)

CREATIONAL DESIGN PATTERNS

CREATIONAL Singleton Ensures class has only one instance with a single access point Simple Factory (Not a true pattern) Encapsulates object creation in one place Factory Method Uses methods to create objects without specifying the exact class Abstract Factory Encapsulates a group of individual factories with a common theme without specifying their concrete class Prototype Clones an instance to make more instances usually for performance reasons

THE SINGLETON PATTERN The singleton pattern is a software design pattern that restricts the instantiation of a class to one instance and provides global access to that instance. Commonly used to implement many other patterns: Factories (abstract and simple), façade, state, builder, and prototype Many DI frameworks provide singleton support You need to understand how the DI f/w works to prevent issues https://en.wikipedia.org/wiki/singleton_pattern

THE SIMPLE FACTORY PATTERN Not a true pattern Encapsulates object creation in one place Should be the only part of the application that refers to concrete classes Reduces duplicate code by enforcing DRY

THE FACTORY METHOD PATTERN The factory method pattern uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes rather than by calling a constructor. https://en.wikipedia.org/wiki/factory_method_pattern

THE ABSTRACT FACTORY PATTERN The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part of the theme. This pattern separates the details of implementation of a set of objects from their general usage and relies on object composition, as object creation is implemented in methods exposed in the factory interface. https://en.wikipedia.org/wiki/abstract_factory_pattern

THE PROTOTYPE PATTERN The prototype pattern is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used to: avoid subclasses of an object creator in the client application, like the abstract factory pattern does. avoid the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) when it is prohibitively expensive for a given application. https://en.wikipedia.org/wiki/prototype_pattern

STRUCTURAL DESIGN PATTERNS

STRUCTURAL Adapter Converts the interface of a class into another interface the client expects Façade Provides a simplified interface to a larger body of code Decorator Attaches additional responsibilities to an object at runtime without effecting othe objects of the same class

THE ADAPTER AND FAÇADE PATTERNS The adapter pattern allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifing code. A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can: Make a software library easier to use, understand, and test, since the facade has convenient methods for common tasks, Reduce dependencies of outside code on the inner workings of a library Wrap a poorly designed collection of APIs with a single well-designed API. https://en.wikipedia.org/wiki/adapter_pattern https://en.wikipedia.org/wiki/facade_pattern

THE DECORATOR PATTERN The decorator pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. Provides an alternative to subclassing for extending functionality. Supports the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concern. https://en.wikipedia.org/wiki/decorator_pattern

BEHAVIORAL DESIGN PATTERNS

BEHAVIORAL Command Encapsulates a request as an object Strategy Encapsulates an algorithm inside a class Observer/Pub-Sub Messaging patterns (see next slide) The Memento Pattern Used to restore an object to its previous state The Template Method Defines skeleton of an algorithm, deferring some steps to sub classes

THE COMMAND PATTERN The command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. Can optionally add Undo Tracked by either the command or the controller Used in conjunction with many other patterns: Factory method, Template method https://en.wikipedia.org/wiki/command_pattern

THE STRATEGY PATTERN The strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables an algorithm's behavior to be selected at runtime. The strategy pattern: defines a family of algorithms, encapsulates each algorithm, and makes the algorithms interchangeable within that family. Promotes the Open/Closed principle by using Composition over Inheritance Examples: Sorting (with custom comparer) Log4Net Fallback Appender https://en.wikipedia.org/wiki/strategy_pattern

THE OBSERVER PATTERN The observer pattern is a pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. Can cause memory leaks due to strong references This is mitigated with weak references https://en.wikipedia.org/wiki/observer_pattern

THE PUBLISH-SUBSCRIBE PATTERN In software architecture, publish subscribe is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead characterize published messages into classes without knowledge of which subscribers, if any, there may be. Similarly, subscribers express interest in one or more classes and only receive messages that are of interest, without knowledge of which publishers, if any, there are. https://en.wikipedia.org/wiki/publish subscribe_pattern

OBSERVER VS PUB-SUB Observer Sender and recipients know each other Send and receive one at a time Direct communication Pub-Sub Sender and recipients unknown to each other Send once, every subject receives. Intermediary handles filtering and routing

THE MEMENTO PATTERN The memento pattern provides the ability to restore an object to its previous state (undo via rollback). The memento pattern is implemented with three objects: the originator, a caretaker and a memento. The originator is some object that has an internal state. The caretaker is going to do something to the originator, but wants to be able to undo the change. It asks for a memento object. Then it does whatever operation (or sequence of operations) it is going to do. To roll back to the state before the operations, it returns the memento object to the originator. https://en.wikipedia.org/wiki/memento_pattern

THE TEMPLATE METHOD PATTERN The template method pattern defines the program skeleton of an algorithm in an operation, deferring some steps to subclasses. It lets one redefine certain steps of an algorithm without changing the algorithm's structure. In the template method, one or more algorithm steps can be overridden by subclasses to allow differing behaviors while ensuring that the overarching algorithm is still followed. https://en.wikipedia.org/wiki/template_method_pattern

RESOURCES Design Patterns: Elements of Reusable Object Oriented Design Eric Gamma, Richard Helm, Ralph Johnson, John Vlissides Head First Design Patterns Freeman, Robson, Bates, Sierra Eight part series with Robert Green on Visual Studio Toolbox https://channel9.msdn.com/shows/visual-studio-toolbox/design-patterns- CommandMemento (first of the series)

Patterns in C#

Contact Me skimedic@outlook.com www.skimedic.com/blog www.twitter.com/skimedic http://bit.ly/skimediclyndacourses http://bit.ly/apressbooks www.hallwayconversations.com Questions?