SlideShare a Scribd company logo
GOF DESIGN PATTERNS I:
INTRODUCTION +
STRUCTURAL PATTERNS
Sameh M. Deabes
AGENDA
Patterns and Anti-patterns
How to learn design patterns?
Categories of GoF patterns
The Fundamental theorem of software engineering
Real-world problems and how design patterns solve them
Uncovered Structural Patterns
Summary
PATTERNS AND ANTI-PATTERNS
What is a design pattern?
 Well-known good high-level abstract solution templates for common problems
 Blueprints not actual solutions
 No pre-baked solution, you will implement it yourself
 Built on concepts of OOP  notice the wide usage of polymorphism
 Caution: don’t try to apply design patterns on every problem you face, rather
“refactor to patterns” better!
What is an anti-pattern?
 Well-known quick high-level abstract solution templates for common problems that
prove to have extensibility/flexibility limitations.
 Quick not correct solutions
 Don’t be afraid to use them given that you justify their usage, and you consider refactoring to patterns.
[KISS, YAGNI]
It’s a matter of right vs quick solution.
HOW TO LEARN DESIGN
PATTERNS?
Problem with GoF book
 The original text groups patterns in three categories, and then alphabetically within
each. All good for reference purposes, but lousy for learning. -- Michael Mahemoff
Solution: use other learning path
 GoF Design Patterns: Rapid Learning Tips, Michael Mahemoff [Article, 2 pages]
 http://cs.millersville.edu/~ekatz/cs420/designPatterns/MamehoffRapidLearning.pdf
 Head First Design patterns, Freeman [book]
 Professional ASP.NET design patterns, Scott Millet [book]
 My own learning path 
 GoF categories
 Problem-Solving approach
 Similarity/differences
LEVELS OF DESIGN PATTERNS
I: Design Patterns: Elements of Reusable Object-Oriented Software,
GoF [23 patterns]
II: Patterns of Enterprise Application Architecture, Martin Fowler
III: Enterprise Integration Patterns, Gregor Hohpe
Problem specific patterns
 SOA patterns
 Concurrency patterns
 …etc.
CATEGORIES OF GOF PATTERNS
Creational patterns
 Objects construction and decoupling
Structural patterns
 How to shape objects to build more complex objects?
Behavioral patterns
 Communication between objects, SoC, and algorithms.
THE FUNDAMENTAL THEOREM OF
SOFTWARE ENGINEERING
We can solve any problem by introducing an extra level of indirection
– David Wheeler
…except for the problem of too many levels of indirection – Kevlin
Henney
THE IDEA OF “WRAPPING”
We will depend on this idea a lot here, then it worth have an example:
STARTING POINT: LOCAL OBJECT
WHAT IF THE OBJECT IS LOCATED
REMOTELY?
WCF SERVICES
Consuming WCF service in y@ our client application
WCF CLIENT AUTO-GENERATED
CODE• The remote object is wrapped by a local object!
• The web service proxies generated by svcutil.exe and deriving
from System.ServiceModel.ClientBase<TChannel>
NOTES
A layer of indirection/wrapper was created to solve the problem.
The interface was adhered.
The wrapper located at my system to wrap remote object
Congrats! This is the first design pattern, Proxy Pattern (typically,
remote proxy)
More examples:
 When you consume a WebApi service that has no wsdl, you create your own proxy
 When you create a SignalR windows client and you create your own proxy
Another flavor = Reverse Proxy: proxy for external systems to use my
services
 The wrapper located at the remote system to control access to its internal objects
WHAT IF THE OBJECT IS EXPENSIVE?
NAVIGATION PROPERTIES IN
ENTITY FRAMEWORK.
EF inherits the class at runtime and adds its implementation to
support lazy loading of navigation properties
NOTES
A layer of indirection was created to solve the problem.
The interface was adhered.
Congrats! This is another flavor of Proxy Pattern (typically, virtual
proxy)
More examples:
 Mocking frameworks @ unit tests makes intensive use of this idea.
WHAT IF WE WANT TO
CHANGE/EXTEND OBJECT BEHAVIOR
AT RUNTIME?
INHERITANCE AND COMPOSITION
Basic OOP solution: derive a sub-class and override methods
implementation you want to change.
One step forward solution (better for most cases):
 Favor composition over inheritance
 Composition = wrap the object by another object
 Composition is superior to inheritance not because of the sake of itself, but because it allows to handle
orthogonal concerns separately  will be obvious in Bridge pattern in a following session.
 Or, in S.O.L.I.D. principles: Open/Closed Principle = Classes should be open to
extension, but closed to changes
 Implement a shared interface + inject an instance of the class that we want to
change its behavior
STREAMS IN .NET FRAMEWORK
NOTES
A layer of indirection was created to solve the problem.
The interface was adhered.
Congrats! This is the Decorator Pattern
Decorator is a special case of proxy (also known as Smart Proxy)
More real-world examples:
 ASP.NET MVC has only one resolver, to support more than one: create a single class
that wraps many resolvers, and forward calls to appropriate resolvers among them.
 @ WPF: System.Windows.Controls.Decorator uses the same idea.
WHAT IF MY CODE DEPENDS ON
OTHER SYSTEM THAT DOESN’T EXIST
YET?!
DON’T STUCK!
Before the dependent system exists:
 Create an interface that spells the behavior you need.
 Create a dummy implementation that adheres this interface and returns dummy
data to be able to test your system
 Use the dummy object in your system
Once the dependent system exists:
 Create a new class that adheres the interface you created before
 Wraps the object that do the actual business, and forward calls to it
 Replace the dummy object by this object in your system.
WHAT IF I NEED TO USE OBJECTS
WITH DIFFERENT INTERFACES
INTERCHANGEABLY?!
AGAIN…DON’T STUCK!
Create an interface that matches the behavior you need.
Wrap every incompatible object with a new class that adheres the
interface and forward calls to the underlying object.
Use the desired wrapper in your system (DI/IoC will be useful here!)
Real-world examples:
 GIS application that needs to use Google maps and MS Virtual Maps
interchangeably!
 Creating an anti-corruption layer for a third-party to enable replacing it in future
 OOD principle: design for replacement not for reusability!
 E.g. Create an ILog interface, and an adapter for Log4Net, Nlog, ..etc.
CODE EXAMPLE
NOTES
Congrats! This is the Adapter Pattern (also known as
wrapper)
 This is one of the most useful patterns!
The interface was NOT adhered
 actually the adapter pattern enables classes of incompatible interfaces to be used
together by converting the interface of a class into another interface that my system
expects.
Usually used to avoid changing existing classes by – again - adding a
layer of indirection!
 Optimum when this class is a third-party that you have no control over its code
Examples from .NET world:
 ADO.NET providers, e.g. System.Data.SqlClient.SqlConnection,
System.Data.OleDb.OleDbConnection etc. Each provider is an adapter for its
specific database.
WHAT IF WE NEED TO SIMPLIFY THE
INTERFACE OF A
COMPLEX SUBSYSTEM OR GROUP OF
SUBSYSTEMS?
ADAPTER++
• Do as you did in Adapter BUT wrap multiple objects:
• Create a class that wraps all objects you need to expose
• Define your simple interface
• Forward calls to underlying objects.
EXAMPLE FROM .NET FRAMEWORK
WELCOME TO UML
NOTES
Congrats! This is the Façade Pattern
 This is one of the most useful patterns!
A layer of indirection was created to solve the problem.
The interface was NOT adhered
Similar enterprise pattern: Transaction Script
 Used in service layer
 = Façade + Transaction (atomic/all or none)
More real-world examples:
 Login to windows with fingerprint and AD
 A single method that calls each pre-existing service successively and return a single result!
YOU HAVE A TREE/HIERARCHY OF
ITEMS/PEOPLE AND YOU NEED TO DO
OPERATIONS ON ALL OF THEM, AT ALL
LEVELS.
THINK OF ORGANIZATION CHART AND
ATTENDANCE CALCULATIONS.
POSSIBLE SOLUTIONS
Wrong solution:
 nested for-loops and lengthy code
Perfect solution:
 Group objects into tree-like or hierarchical collection
 Each node in the tree is responsible of its own operations
 Call the root node, which calls the nested nodes recursively to complete the
operation.
 The important point is that each node is responsible of its own calculations
EXAMPLE
RESULTS
NOTES
Congrats! This is the Composite pattern!
More examples from .NET framework:
 System.Windows.Forms.Control
 System.Web.UI.Control
 System.Xml.XmlNode
UNCOVERED STRUCTURAL
PATTERNS
Bridge pattern
 It is a mix of Template and Strategy Behavioral patterns, thus postponed till we
learn these patterns.
Flyweight
 Depends on Factory Creational pattern, thus postponed till we learn this pattern.
SUMMARY
Right vs Quick solutions = Patterns vs Anti-patterns
Important OOD principles
 We can solve any problem by introducing an extra level of indirection except for the problem of too many
levels of indirection
 Favor composition over inheritance
 Open/Closed Principle = Classes should be open to extension, but closed to changes
 Design for replacement not for reusability!
Covered GoF Structural Patterns
 Proxy
 Decorator
 Adapter
 Façade
 Composite
Uncovered GoF Structural Patterns
 Bridge
 Flyweight
Ad

More Related Content

What's hot (20)

Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
Oğuzhan Soykan
 
Design patterns
Design patternsDesign patterns
Design patterns
abhisheksagi
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
University of Technology
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
Amit Kabra
 
Design patterns
Design patternsDesign patterns
Design patterns
Elyes Mejri
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
Anton Keks
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
paramisoft
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
Sujata Regoti
 
Introduction to DDD
Introduction to DDDIntroduction to DDD
Introduction to DDD
Eduards Sizovs
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nader Albert
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
Edureka!
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
Paul Mooney
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Abstract class
Abstract classAbstract class
Abstract class
Tony Nguyen
 
Software Architecture and Design
Software Architecture and DesignSoftware Architecture and Design
Software Architecture and Design
Ra'Fat Al-Msie'deen
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
Assaf Gannon
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
Rana Muhammad Asif
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
thinkddd
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
Oğuzhan Soykan
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
Amit Kabra
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
Anton Keks
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
paramisoft
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
Sujata Regoti
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nader Albert
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
Edureka!
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
Paul Mooney
 
Software Architecture and Design
Software Architecture and DesignSoftware Architecture and Design
Software Architecture and Design
Ra'Fat Al-Msie'deen
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
Assaf Gannon
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
thinkddd
 

Viewers also liked (12)

introduction-to-gprs-egprs-
introduction-to-gprs-egprs-introduction-to-gprs-egprs-
introduction-to-gprs-egprs-
Dawood Aqlan
 
Multiband Transceivers - [Chapter 7] Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...
Multiband Transceivers - [Chapter 7]  Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...Multiband Transceivers - [Chapter 7]  Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...
Multiband Transceivers - [Chapter 7] Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...
Simen Li
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
Chetan Gole
 
Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...
Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...
Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...
Justin Basilico
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
Saurabh Moody
 
GPRS
GPRSGPRS
GPRS
Object-Frontier Software Pvt. Ltd
 
Quick Summary of LTE Voice Summit 2014 #LTEVoice
Quick Summary of LTE Voice Summit 2014 #LTEVoiceQuick Summary of LTE Voice Summit 2014 #LTEVoice
Quick Summary of LTE Voice Summit 2014 #LTEVoice
eXplanoTech
 
5G: A 2020 Vision
5G: A 2020 Vision5G: A 2020 Vision
5G: A 2020 Vision
eXplanoTech
 
Gprs architecture ppt
Gprs architecture pptGprs architecture ppt
Gprs architecture ppt
Arpita Sanghani
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
Ender Aydin Orak
 
Gprs ppt
Gprs pptGprs ppt
Gprs ppt
Shams Tabrez
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
Herman Peeren
 
introduction-to-gprs-egprs-
introduction-to-gprs-egprs-introduction-to-gprs-egprs-
introduction-to-gprs-egprs-
Dawood Aqlan
 
Multiband Transceivers - [Chapter 7] Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...
Multiband Transceivers - [Chapter 7]  Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...Multiband Transceivers - [Chapter 7]  Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...
Multiband Transceivers - [Chapter 7] Multi-mode/Multi-band GSM/GPRS/TDMA/AMP...
Simen Li
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
Chetan Gole
 
Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...
Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...
Is that a Time Machine? Some Design Patterns for Real World Machine Learning ...
Justin Basilico
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
Saurabh Moody
 
Quick Summary of LTE Voice Summit 2014 #LTEVoice
Quick Summary of LTE Voice Summit 2014 #LTEVoiceQuick Summary of LTE Voice Summit 2014 #LTEVoice
Quick Summary of LTE Voice Summit 2014 #LTEVoice
eXplanoTech
 
5G: A 2020 Vision
5G: A 2020 Vision5G: A 2020 Vision
5G: A 2020 Vision
eXplanoTech
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
Ender Aydin Orak
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
Herman Peeren
 
Ad

Similar to GoF Design patterns I: Introduction + Structural Patterns (20)

L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
Ólafur Andri Ragnarsson
 
L03 Design Patterns
L03 Design PatternsL03 Design Patterns
L03 Design Patterns
Ólafur Andri Ragnarsson
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
Ólafur Andri Ragnarsson
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software Engineering
Protelo, Inc.
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Prageeth Sandakalum
 
Design pattern
Design patternDesign pattern
Design pattern
Shreyance Jain
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
agnes_crepet
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
RookieOne
 
Clean code-v2.2
Clean code-v2.2Clean code-v2.2
Clean code-v2.2
Bình Trọng Án
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
jinaldesailive
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
Bp301
Bp301Bp301
Bp301
Bill Buchan
 
Clean Code .Net Cheetsheets
Clean Code .Net CheetsheetsClean Code .Net Cheetsheets
Clean Code .Net Cheetsheets
NikitaGoncharuk1
 
Design patterns
Design patternsDesign patterns
Design patterns
mudabbirwarsi
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
BADR
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
Antonio Terreno
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software Engineering
Protelo, Inc.
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
agnes_crepet
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
RookieOne
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
jinaldesailive
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
Clean Code .Net Cheetsheets
Clean Code .Net CheetsheetsClean Code .Net Cheetsheets
Clean Code .Net Cheetsheets
NikitaGoncharuk1
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
BADR
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
Antonio Terreno
 
Ad

Recently uploaded (20)

Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 

GoF Design patterns I: Introduction + Structural Patterns

  • 1. GOF DESIGN PATTERNS I: INTRODUCTION + STRUCTURAL PATTERNS Sameh M. Deabes
  • 2. AGENDA Patterns and Anti-patterns How to learn design patterns? Categories of GoF patterns The Fundamental theorem of software engineering Real-world problems and how design patterns solve them Uncovered Structural Patterns Summary
  • 3. PATTERNS AND ANTI-PATTERNS What is a design pattern?  Well-known good high-level abstract solution templates for common problems  Blueprints not actual solutions  No pre-baked solution, you will implement it yourself  Built on concepts of OOP  notice the wide usage of polymorphism  Caution: don’t try to apply design patterns on every problem you face, rather “refactor to patterns” better! What is an anti-pattern?  Well-known quick high-level abstract solution templates for common problems that prove to have extensibility/flexibility limitations.  Quick not correct solutions  Don’t be afraid to use them given that you justify their usage, and you consider refactoring to patterns. [KISS, YAGNI] It’s a matter of right vs quick solution.
  • 4. HOW TO LEARN DESIGN PATTERNS? Problem with GoF book  The original text groups patterns in three categories, and then alphabetically within each. All good for reference purposes, but lousy for learning. -- Michael Mahemoff Solution: use other learning path  GoF Design Patterns: Rapid Learning Tips, Michael Mahemoff [Article, 2 pages]  http://cs.millersville.edu/~ekatz/cs420/designPatterns/MamehoffRapidLearning.pdf  Head First Design patterns, Freeman [book]  Professional ASP.NET design patterns, Scott Millet [book]  My own learning path   GoF categories  Problem-Solving approach  Similarity/differences
  • 5. LEVELS OF DESIGN PATTERNS I: Design Patterns: Elements of Reusable Object-Oriented Software, GoF [23 patterns] II: Patterns of Enterprise Application Architecture, Martin Fowler III: Enterprise Integration Patterns, Gregor Hohpe Problem specific patterns  SOA patterns  Concurrency patterns  …etc.
  • 6. CATEGORIES OF GOF PATTERNS Creational patterns  Objects construction and decoupling Structural patterns  How to shape objects to build more complex objects? Behavioral patterns  Communication between objects, SoC, and algorithms.
  • 7. THE FUNDAMENTAL THEOREM OF SOFTWARE ENGINEERING We can solve any problem by introducing an extra level of indirection – David Wheeler …except for the problem of too many levels of indirection – Kevlin Henney
  • 8. THE IDEA OF “WRAPPING” We will depend on this idea a lot here, then it worth have an example:
  • 10. WHAT IF THE OBJECT IS LOCATED REMOTELY?
  • 11. WCF SERVICES Consuming WCF service in y@ our client application
  • 12. WCF CLIENT AUTO-GENERATED CODE• The remote object is wrapped by a local object! • The web service proxies generated by svcutil.exe and deriving from System.ServiceModel.ClientBase<TChannel>
  • 13. NOTES A layer of indirection/wrapper was created to solve the problem. The interface was adhered. The wrapper located at my system to wrap remote object Congrats! This is the first design pattern, Proxy Pattern (typically, remote proxy) More examples:  When you consume a WebApi service that has no wsdl, you create your own proxy  When you create a SignalR windows client and you create your own proxy Another flavor = Reverse Proxy: proxy for external systems to use my services  The wrapper located at the remote system to control access to its internal objects
  • 14. WHAT IF THE OBJECT IS EXPENSIVE?
  • 15. NAVIGATION PROPERTIES IN ENTITY FRAMEWORK. EF inherits the class at runtime and adds its implementation to support lazy loading of navigation properties
  • 16. NOTES A layer of indirection was created to solve the problem. The interface was adhered. Congrats! This is another flavor of Proxy Pattern (typically, virtual proxy) More examples:  Mocking frameworks @ unit tests makes intensive use of this idea.
  • 17. WHAT IF WE WANT TO CHANGE/EXTEND OBJECT BEHAVIOR AT RUNTIME?
  • 18. INHERITANCE AND COMPOSITION Basic OOP solution: derive a sub-class and override methods implementation you want to change. One step forward solution (better for most cases):  Favor composition over inheritance  Composition = wrap the object by another object  Composition is superior to inheritance not because of the sake of itself, but because it allows to handle orthogonal concerns separately  will be obvious in Bridge pattern in a following session.  Or, in S.O.L.I.D. principles: Open/Closed Principle = Classes should be open to extension, but closed to changes  Implement a shared interface + inject an instance of the class that we want to change its behavior
  • 19. STREAMS IN .NET FRAMEWORK
  • 20. NOTES A layer of indirection was created to solve the problem. The interface was adhered. Congrats! This is the Decorator Pattern Decorator is a special case of proxy (also known as Smart Proxy) More real-world examples:  ASP.NET MVC has only one resolver, to support more than one: create a single class that wraps many resolvers, and forward calls to appropriate resolvers among them.  @ WPF: System.Windows.Controls.Decorator uses the same idea.
  • 21. WHAT IF MY CODE DEPENDS ON OTHER SYSTEM THAT DOESN’T EXIST YET?!
  • 22. DON’T STUCK! Before the dependent system exists:  Create an interface that spells the behavior you need.  Create a dummy implementation that adheres this interface and returns dummy data to be able to test your system  Use the dummy object in your system Once the dependent system exists:  Create a new class that adheres the interface you created before  Wraps the object that do the actual business, and forward calls to it  Replace the dummy object by this object in your system.
  • 23. WHAT IF I NEED TO USE OBJECTS WITH DIFFERENT INTERFACES INTERCHANGEABLY?!
  • 24. AGAIN…DON’T STUCK! Create an interface that matches the behavior you need. Wrap every incompatible object with a new class that adheres the interface and forward calls to the underlying object. Use the desired wrapper in your system (DI/IoC will be useful here!) Real-world examples:  GIS application that needs to use Google maps and MS Virtual Maps interchangeably!  Creating an anti-corruption layer for a third-party to enable replacing it in future  OOD principle: design for replacement not for reusability!  E.g. Create an ILog interface, and an adapter for Log4Net, Nlog, ..etc.
  • 26. NOTES Congrats! This is the Adapter Pattern (also known as wrapper)  This is one of the most useful patterns! The interface was NOT adhered  actually the adapter pattern enables classes of incompatible interfaces to be used together by converting the interface of a class into another interface that my system expects. Usually used to avoid changing existing classes by – again - adding a layer of indirection!  Optimum when this class is a third-party that you have no control over its code Examples from .NET world:  ADO.NET providers, e.g. System.Data.SqlClient.SqlConnection, System.Data.OleDb.OleDbConnection etc. Each provider is an adapter for its specific database.
  • 27. WHAT IF WE NEED TO SIMPLIFY THE INTERFACE OF A COMPLEX SUBSYSTEM OR GROUP OF SUBSYSTEMS?
  • 28. ADAPTER++ • Do as you did in Adapter BUT wrap multiple objects: • Create a class that wraps all objects you need to expose • Define your simple interface • Forward calls to underlying objects.
  • 29. EXAMPLE FROM .NET FRAMEWORK
  • 31. NOTES Congrats! This is the Façade Pattern  This is one of the most useful patterns! A layer of indirection was created to solve the problem. The interface was NOT adhered Similar enterprise pattern: Transaction Script  Used in service layer  = Façade + Transaction (atomic/all or none) More real-world examples:  Login to windows with fingerprint and AD  A single method that calls each pre-existing service successively and return a single result!
  • 32. YOU HAVE A TREE/HIERARCHY OF ITEMS/PEOPLE AND YOU NEED TO DO OPERATIONS ON ALL OF THEM, AT ALL LEVELS. THINK OF ORGANIZATION CHART AND ATTENDANCE CALCULATIONS.
  • 33. POSSIBLE SOLUTIONS Wrong solution:  nested for-loops and lengthy code Perfect solution:  Group objects into tree-like or hierarchical collection  Each node in the tree is responsible of its own operations  Call the root node, which calls the nested nodes recursively to complete the operation.  The important point is that each node is responsible of its own calculations
  • 36. NOTES Congrats! This is the Composite pattern! More examples from .NET framework:  System.Windows.Forms.Control  System.Web.UI.Control  System.Xml.XmlNode
  • 37. UNCOVERED STRUCTURAL PATTERNS Bridge pattern  It is a mix of Template and Strategy Behavioral patterns, thus postponed till we learn these patterns. Flyweight  Depends on Factory Creational pattern, thus postponed till we learn this pattern.
  • 38. SUMMARY Right vs Quick solutions = Patterns vs Anti-patterns Important OOD principles  We can solve any problem by introducing an extra level of indirection except for the problem of too many levels of indirection  Favor composition over inheritance  Open/Closed Principle = Classes should be open to extension, but closed to changes  Design for replacement not for reusability! Covered GoF Structural Patterns  Proxy  Decorator  Adapter  Façade  Composite Uncovered GoF Structural Patterns  Bridge  Flyweight