[yidlug] computer/software design patterns
DESCRIPTION
Computer Design Patterns Presented BY: Joel Kaufman Sr Software Engineer, Web Admin Presented BY: Joel Kaufman Sr Software Engineer, Web Admin Joel is familiar with C, C#, java, JavaScript, PHP, VB, vb.net, front-end and back-end developer, great engineering experience, developed and maintained great projects, his passion to design and structure is exceptional. Description: ever found yourself in middle of a big project, that the code looks complicated, hard to debug, hard to add new features, or take out existing features ? ever wondered how a event system works on a operating system ? ever found yourself that a lot of code solves similar problems but can't make just a function to solve it ? YIDLUG is a Yiddish speaking Linux (and other open source software) Users Group, check us out at http://www.meetup.com/yidlugTRANSCRIPT
![Page 1: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/1.jpg)
Welcome to YIDLUG
![Page 2: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/2.jpg)
DESIGN PATTRENS
![Page 3: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/3.jpg)
Agenda
• Do you OOPs?
• Design Patterns? Why
• Design Patterns? What
• Design Patterns? How
![Page 4: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/4.jpg)
why care about all of this
![Page 5: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/5.jpg)
Example of a speaker
![Page 6: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/6.jpg)
The speakers check list
Speak the language
Know how to design a speech
![Page 7: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/7.jpg)
The programmers check list
Know a computer language
Understand a program design
![Page 8: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/8.jpg)
Programming without design
![Page 9: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/9.jpg)
Or worse !
![Page 10: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/10.jpg)
Getting startedRefresh on Object Oriented Programming (OOP)
![Page 11: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/11.jpg)
Normal Classes vs Abstract Classes vs InterfacesNormal Class: This is a normal class
Abstract Class: These cannot be instantiated directly. They may provide partial implementations and exists solely for the purpose of inheritance.
Interfaces: Defines a contract. Concrete implementations needs to implement each property and method as per contract.
![Page 12: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/12.jpg)
Million Dollar Question? What is Why?
![Page 13: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/13.jpg)
Normal Class vs Abstract Class?
If a particular class is a entity which is not
required to be instantiated by the
application directly, go for Abstract Class
Employee can be abstract class
![Page 14: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/14.jpg)
Abstract Class vs Interfaces?
If a particular class contains any default
behavior, go for Abstract Class
If every concrete class has its own
implementation, go forInterfacesWork – Management, Programming
![Page 15: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/15.jpg)
MOVIES & ACTORS
Shahrukh KhanSalman Khan riding bike
Actors in a Movie
![Page 16: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/16.jpg)
IS-A InheritanceShahrukh Khan is an ACTOR
HAS-A CompositionMovie has ACTORS
CAN-DO InterfacesSalman Khan can DRIVE BIKE
IS-A vs HAS-A vs CAN-DO
IS-A InheritanceShahrukh Khan is an ACTOR
HAS-A CompositionMovie has ACTORS
CAN-DO InterfacesSalman Khan can DRIVE BIKE
![Page 17: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/17.jpg)
What is a Pattern
• An 'element of reusable software’
• A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems.
• It describes the problem, the solution, when to apply the solution, and its consequences.
• It also gives implementation hints and examples. The solution is a general arrangement of objects and classes that solve the problem. The solution is customized and implemented to solve the problem in a particular context.
![Page 18: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/18.jpg)
History of Software Patterns
![Page 19: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/19.jpg)
What Wikipedia says,
• A design pattern is a general repeatable solution to a commonly occurring problem in software design.
• A design pattern is not a finished design that can be transformed directly into code.
• Algorithms are not thought of as design patterns.
![Page 20: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/20.jpg)
Let’s understand the purpose
![Page 21: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/21.jpg)
Let’s understand design patterns by purpose
![Page 22: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/22.jpg)
Let’s understand the purpose
+
Creational Patterns
Structural Patterns
Final Product
Behavioral Patterns
![Page 23: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/23.jpg)
Design Patterns as per their PURPOSE
![Page 24: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/24.jpg)
Creational Patterns
![Page 25: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/25.jpg)
Factory Method
![Page 26: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/26.jpg)
Factory Method Provide an interface for the creation of objects. Allow subclasses to “decide” which class to instantiate.
![Page 27: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/27.jpg)
Factory Method
Define an interface for creating an object, but let subclass decide which class to instantiate
• Prevents creation of any additional instances, while simultaneously allowing global access
• Creation can be delayed until it is actually required
![Page 28: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/28.jpg)
Abstract Factory Pattern
![Page 29: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/29.jpg)
Abstract Factory Pattern
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
• Provides creation of families of related or dependent objects without specifying their concrete class
![Page 30: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/30.jpg)
Abstract Factory Povide an interface for creating families of related or dependent objects. A factory for factories.
![Page 31: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/31.jpg)
Singleton Ensure a class only has one instance, and provide a global point of access to it.
![Page 32: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/32.jpg)
Prototype Make variations on copies of a basic-object.
![Page 33: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/33.jpg)
Structural Patterns
![Page 34: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/34.jpg)
Façade Pattern
![Page 35: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/35.jpg)
Façade Pattern
Provide a unified interface to set of interfaces in a subsystem.
• Is generally one side of the exterior of a building, especially the front
• Origin from a FRENCH word means “face” or “front”
![Page 36: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/36.jpg)
Façade Pattern
Its all about the service
![Page 37: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/37.jpg)
Decorator Pattern
![Page 38: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/38.jpg)
Decorator Pattern
Attach additional responsibilities to an object dynamically.
• Flexible alternative to subclassing for extending functionality
• Allows dynamic and transparent addition and removal of responsibilities without affecting object
simple actress(act)
in role of modern girl(go out and act)
in role of homely girl(be in home and act)
![Page 39: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/39.jpg)
Composite Pattern
![Page 40: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/40.jpg)
Composite Pattern
Compose objects into tree structures to represent part-whole hierarchies
• When dealing with collections of objects, there are often operations that are appropriate for both a single object and the entire collection
• Treats individual objects and composition of objects uniformly
Example: a)Every object “IS-A” shapeb)Every shape “HAS-A” draw behavior
![Page 41: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/41.jpg)
Adapter Pattern
![Page 42: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/42.jpg)
Adapter Pattern
Convert the interface of a class into another interface clients expect
• Lets classes work together that couldn’t work otherwise
• Works good for making compliance
ApplicationFrameworkAdapter
LegacyComponent
![Page 43: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/43.jpg)
Decorator vs Adapter
Decorator looks like Adapter which “decorates” an existing class to make it compatible. Though, Decorator doesn’t wants you to decorate every method in the Adapted class. But who has stopped from doing it.
“Never underestimate the power of a developer”
![Page 44: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/44.jpg)
Decorator vs Façade
Façade is a way of hiding a complex system inside a simpler interface, whereas Decorator adds function by wrapping a class.
![Page 45: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/45.jpg)
Behavioural Patterns
![Page 46: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/46.jpg)
Command Pattern
![Page 47: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/47.jpg)
Command Pattern
Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests.
• If all commands can service a specific request, they can be entertained by the invoker
• Concrete command performs the action on Receiver
• Encapsulate method invocation
One Receiver
andMultiple actions
![Page 48: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/48.jpg)
Strategy Pattern
![Page 49: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/49.jpg)
Strategy Pattern
Define strategies for a performing a behavior and change them dynamically as per requirement
• This lets the algorithm vary independently from clients that uses it
• It is about choice, which affects outcomes
![Page 50: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/50.jpg)
Template Method
![Page 51: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/51.jpg)
Template Method
Define the skeleton of an algorithm in an operations, deferring some steps to subclass
• Main algorithm skeleton is defined in a base class and subclasses can then plug in their own details without affecting the algorithm itself
• Uses Inheritance – Abstract Class defines the template (algorithm) and Concrete class manages the implementation.
• Template uses the implementation on demand
![Page 52: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/52.jpg)
Strategy Pattern vs Template Method• Strategy allows callers to change the algorithm or order of steps whereas Template method allow steps to be modified
• Strategy uses Interfaces whereas Template method uses Inheritance
![Page 53: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/53.jpg)
CONTENT STOLEN FROM
BOOKS:
Head First Design Patterns
Design Patterns in C#
Design Patterns
WEBSITES:
Wikipedia, MSDN, doFactory and GOOGLE
![Page 54: [YIDLUG] Computer/Software Design patterns](https://reader034.vdocuments.net/reader034/viewer/2022051818/54b7aac24a7959d3328b45f0/html5/thumbnails/54.jpg)
Answers, anybody?