SlideShare a Scribd company logo
DESIGN PATTERNS
AHMAD HUSSEIN
1ahmadhussein.ah7@gmail.com
LAZY LOADING
2
DEFINITION
"Lazy loading is a design pattern commonly used in
computer programming to defer initialization of an
object until the point at which it is needed. It can
contribute to efficiency in the program's operation
if properly and appropriately used. The opposite of
lazy loading is eager loading.“
-- Wikipedia
3
WHAT DOES THAT MEAN?
You want to be as lazy as possible, and hope that
someone else comes along and does all the work for
you.
4
WAIT WHAT?
Lazy loading really means waiting to get data or
process an object until you need it; not before. If you
get data before and it's never used, the time it took
was wasted. Also, getting all your data up front can
make the user think the application is slow or
unresponsive at first. Deferring certain
data/processing to lazy load lets your application
focus on more immediate/important code.
5
SIMPLE EXAMPLE
6
IMPLEMENTATIONS
There are four common implementations:
• Lazy initialization
• Virtual proxy
• Ghost
• Value holder
7
LAZY INITIALIZATION
Constructors are used to construct the member
variables of a class. As soon as the instance of the class is
created the member variables of the class are initialized.
This process seems fine if we have member variables
which don't take huge memory. But suppose if we have a
memory consuming resource and if we are initializing it
as member variable, it can be prove to be memory
hungry process.
To prevent from initializing the member variable as
soon as the instance of class is constructed we can define
member variable as property which can be initialized on
demand(Lazy initialization). Let's check it through code
snippet.
8
LAZY INITIALIZATION
9
LAZY INITIALIZATION
Is the code at the previous slide is thread safe?
Definitely not. What if two threads enter if block at
the same time, we will end up getting different
instance of Hungry for the ResourceConsumer class
which is not a good thing.
To make it thread safe we need to have a lock
outside if block as shown in the following code
snippet.
10
LAZY INITIALIZATION
11
LAZY INITIALIZATION
Lazy<T>
Starting framework 4.0, Lazy<T> class can be used
to help with lazy initialization. If instantiated with
an argument of true, it implements a thread-
safe initialization pattern just described.
To use the Lazy<T>, we need to instantiate the class
with the delegate that tells it how to instantiate a
new value, and the argument true. We need to
access its value via the Value property
12
LAZY INITIALIZATION
13
VIRTUAL PROXY
A virtual proxy object shares an interface with the
"real" object. The first time a property of the virtual
proxy is accessed, the real object gets initialized.
From that point on, accessing properties of the
virtual object returns the corresponding property of
the real object.
This basically combines the Lazy initialization and
Proxy patterns
14
VIRTUAL PROXY
Example:
15
VIRTUAL PROXY
16
VIRTUAL PROXY
17
GHOST
The object is partially loaded, usually only with its
identifier. The rest of the data is loaded the first
time a property is accessed.
18
GHOST
Continue
19
GHOST
20
VALUE HOLDER
A value holder is a generic object that handles the
lazy loading behavior and appears in place of the
object’s data fields. When the user needs to access it,
they simply ask the value holder for its value by
calling the GetValue method. At that time (and only
then), the value gets loaded from a database or
from a service.(this is not always needed).
21
VALUE HOLDER
22
DIFFERENCE BETWEEN ADAPTER
PATTERN, PROXY PATTERN AND
BRIDGE PATTERN
23
ADAPTER PATTERN
• The primary purpose of the adapter pattern is to
change the interface of class/library A to the
expectations of client B.
• The typical implementation is a wrapper class or
set of classes.
• The purpose is not to facilitate future interface
changes, but current interface incompatibilities.
24
STRUCTURE
25
PROXY PATTERN
• The purpose of the proxy pattern is to create a
stand-in for a real resource. There are common
situations in which the Proxy pattern is applicable:
• A virtual proxy is a placeholder for "expensive to
create" objects. The real object is only created when a
client first requests/accesses the object.
• A remote proxy provides a local representative for an
object that resides in a different address space.
• A protective proxy controls access to a sensitive
master object.
26
STRUCTURE
27
KEY DIFFERENCES
• Adapter provides a different interface to its
subject. Proxy provides the same interface.
• Adapter is meant to change the interface of an
existing object.
28
BRIDGE PATTERN
• The Bridge pattern is something you implement up
front - if you know you have two orthogonal
hierarchies, it provides a way to decouple the
interface and the implementation in such a way
that you don't get an insane number of classes.
29
BRIDGE PATTERN
• Let's say you have:
30
STRUCTURE
31
KEY DIFFERENCES
• Adapter makes things work after they're designed;
Bridge makes them work before they are.
• Bridge is designed up-front to let the abstraction
and the implementation vary independently.
Adapter is retrofitted to make unrelated classes
work together.
32
DIFFERENCE BETWEEN FACTORY
PATTERN AND BUILDER PATTERN
33
FACTORY PATTERN
• The factory is in charge of creating various
subtypes of an object depending on the needs.
• The user of a factory method doesn't need to know
the exact subtype of that object. An example of a
factory method createCar might return a Ford or a
Honda typed object.
34
STRUCTURE
35
BUILDER PATTERN
• In the Builder pattern, different subtypes are also
created by a builder method, but the composition
of the objects might differ within the same
subclass.
• To continue the car example you might have a
createCar builder method which creates a Honda
typed object with a 4 cylinder engine, or a Honda
typed object with 6 cylinders. The builder pattern
allows for this finer granularity.
36
STRUCTURE
37

More Related Content

What's hot

Proxy pattern
Proxy patternProxy pattern
Proxy pattern
Shakil Ahmed
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
paramisoft
 
Dependency Injection Lightning Talk
Dependency Injection Lightning TalkDependency Injection Lightning Talk
Dependency Injection Lightning Talk
Jon Bachelor
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patterns
sgleadow
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
Huy Hoàng Phạm
 
Design pattern
Design patternDesign pattern
Design pattern
Mallikarjuna G D
 
SOLID Software Principles with C#
SOLID Software Principles with C#SOLID Software Principles with C#
SOLID Software Principles with C#
Ken Burkhardt
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript Development
Addy Osmani
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Jaswant Singh
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Jyaasa Technologies
 
Design Patterns in iOS
Design Patterns in iOSDesign Patterns in iOS
Design Patterns in iOS
Yi-Shou Chen
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
Jiby John
 
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
 
Building Large Scale Javascript Application
Building Large Scale Javascript ApplicationBuilding Large Scale Javascript Application
Building Large Scale Javascript Application
Anis Ahmad
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
Nicholas Zakas
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8
valuebound
 
Factory method pattern
Factory method patternFactory method pattern
Factory method pattern
Shahriar Iqbal Chowdhury
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere Miklos Csere
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed PrincipleSam Hennessy
 
Creating and destroying objects
Creating and destroying objectsCreating and destroying objects
Creating and destroying objects
Sandeep Chawla
 

What's hot (20)

Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Dependency Injection Lightning Talk
Dependency Injection Lightning TalkDependency Injection Lightning Talk
Dependency Injection Lightning Talk
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patterns
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Design pattern
Design patternDesign pattern
Design pattern
 
SOLID Software Principles with C#
SOLID Software Principles with C#SOLID Software Principles with C#
SOLID Software Principles with C#
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript Development
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Design Patterns in iOS
Design Patterns in iOSDesign Patterns in iOS
Design Patterns in iOS
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
 
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
 
Building Large Scale Javascript Application
Building Large Scale Javascript ApplicationBuilding Large Scale Javascript Application
Building Large Scale Javascript Application
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8
 
Factory method pattern
Factory method patternFactory method pattern
Factory method pattern
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed Principle
 
Creating and destroying objects
Creating and destroying objectsCreating and destroying objects
Creating and destroying objects
 

Similar to Design Patterns

Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
Sergey Aganezov
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2
Sanket Shah
 
50 common web developer interview questions [2020 updated] [www.full stack....
50 common web developer interview questions [2020 updated]   [www.full stack....50 common web developer interview questions [2020 updated]   [www.full stack....
50 common web developer interview questions [2020 updated] [www.full stack....
Alex Ershov
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
meghantaylor
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014Lari Hotari
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Theo Jungeblut
 
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
 
Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014
Greg Szczotka
 
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
cNguyn506241
 
Polaris presentation ioc - code conference
Polaris presentation   ioc - code conferencePolaris presentation   ioc - code conference
Polaris presentation ioc - code conference
Steven Contos
 
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
Unity Technologies Japan K.K.
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
Neelima Sanagavarapu
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questions
AniketBhandare2
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
Mohammad Hossein Rimaz
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
Ortus Solutions, Corp
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
Robin O'Brien
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Theo Jungeblut
 

Similar to Design Patterns (20)

Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2
 
50 common web developer interview questions [2020 updated] [www.full stack....
50 common web developer interview questions [2020 updated]   [www.full stack....50 common web developer interview questions [2020 updated]   [www.full stack....
50 common web developer interview questions [2020 updated] [www.full stack....
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
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
 
Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014
 
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
 
Polaris presentation ioc - code conference
Polaris presentation   ioc - code conferencePolaris presentation   ioc - code conference
Polaris presentation ioc - code conference
 
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questions
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
 

More from Ahmad Hussein

Knowledge Representation Methods
Knowledge Representation MethodsKnowledge Representation Methods
Knowledge Representation Methods
Ahmad Hussein
 
Knowledge-Base Systems Homework - 2019
Knowledge-Base Systems Homework - 2019Knowledge-Base Systems Homework - 2019
Knowledge-Base Systems Homework - 2019
Ahmad Hussein
 
Knowledge based systems homework
Knowledge based systems homeworkKnowledge based systems homework
Knowledge based systems homework
Ahmad Hussein
 
Expert system with python -2
Expert system with python  -2Expert system with python  -2
Expert system with python -2
Ahmad Hussein
 
Expert System With Python -1
Expert System With Python -1Expert System With Python -1
Expert System With Python -1
Ahmad Hussein
 
Python introduction 2
Python introduction 2Python introduction 2
Python introduction 2
Ahmad Hussein
 
Python introduction 1
Python introduction 1  Python introduction 1
Python introduction 1
Ahmad Hussein
 

More from Ahmad Hussein (7)

Knowledge Representation Methods
Knowledge Representation MethodsKnowledge Representation Methods
Knowledge Representation Methods
 
Knowledge-Base Systems Homework - 2019
Knowledge-Base Systems Homework - 2019Knowledge-Base Systems Homework - 2019
Knowledge-Base Systems Homework - 2019
 
Knowledge based systems homework
Knowledge based systems homeworkKnowledge based systems homework
Knowledge based systems homework
 
Expert system with python -2
Expert system with python  -2Expert system with python  -2
Expert system with python -2
 
Expert System With Python -1
Expert System With Python -1Expert System With Python -1
Expert System With Python -1
 
Python introduction 2
Python introduction 2Python introduction 2
Python introduction 2
 
Python introduction 1
Python introduction 1  Python introduction 1
Python introduction 1
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 

Recently uploaded (20)

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 

Design Patterns

  • 3. DEFINITION "Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. The opposite of lazy loading is eager loading.“ -- Wikipedia 3
  • 4. WHAT DOES THAT MEAN? You want to be as lazy as possible, and hope that someone else comes along and does all the work for you. 4
  • 5. WAIT WHAT? Lazy loading really means waiting to get data or process an object until you need it; not before. If you get data before and it's never used, the time it took was wasted. Also, getting all your data up front can make the user think the application is slow or unresponsive at first. Deferring certain data/processing to lazy load lets your application focus on more immediate/important code. 5
  • 7. IMPLEMENTATIONS There are four common implementations: • Lazy initialization • Virtual proxy • Ghost • Value holder 7
  • 8. LAZY INITIALIZATION Constructors are used to construct the member variables of a class. As soon as the instance of the class is created the member variables of the class are initialized. This process seems fine if we have member variables which don't take huge memory. But suppose if we have a memory consuming resource and if we are initializing it as member variable, it can be prove to be memory hungry process. To prevent from initializing the member variable as soon as the instance of class is constructed we can define member variable as property which can be initialized on demand(Lazy initialization). Let's check it through code snippet. 8
  • 10. LAZY INITIALIZATION Is the code at the previous slide is thread safe? Definitely not. What if two threads enter if block at the same time, we will end up getting different instance of Hungry for the ResourceConsumer class which is not a good thing. To make it thread safe we need to have a lock outside if block as shown in the following code snippet. 10
  • 12. LAZY INITIALIZATION Lazy<T> Starting framework 4.0, Lazy<T> class can be used to help with lazy initialization. If instantiated with an argument of true, it implements a thread- safe initialization pattern just described. To use the Lazy<T>, we need to instantiate the class with the delegate that tells it how to instantiate a new value, and the argument true. We need to access its value via the Value property 12
  • 14. VIRTUAL PROXY A virtual proxy object shares an interface with the "real" object. The first time a property of the virtual proxy is accessed, the real object gets initialized. From that point on, accessing properties of the virtual object returns the corresponding property of the real object. This basically combines the Lazy initialization and Proxy patterns 14
  • 18. GHOST The object is partially loaded, usually only with its identifier. The rest of the data is loaded the first time a property is accessed. 18
  • 21. VALUE HOLDER A value holder is a generic object that handles the lazy loading behavior and appears in place of the object’s data fields. When the user needs to access it, they simply ask the value holder for its value by calling the GetValue method. At that time (and only then), the value gets loaded from a database or from a service.(this is not always needed). 21
  • 23. DIFFERENCE BETWEEN ADAPTER PATTERN, PROXY PATTERN AND BRIDGE PATTERN 23
  • 24. ADAPTER PATTERN • The primary purpose of the adapter pattern is to change the interface of class/library A to the expectations of client B. • The typical implementation is a wrapper class or set of classes. • The purpose is not to facilitate future interface changes, but current interface incompatibilities. 24
  • 26. PROXY PATTERN • The purpose of the proxy pattern is to create a stand-in for a real resource. There are common situations in which the Proxy pattern is applicable: • A virtual proxy is a placeholder for "expensive to create" objects. The real object is only created when a client first requests/accesses the object. • A remote proxy provides a local representative for an object that resides in a different address space. • A protective proxy controls access to a sensitive master object. 26
  • 28. KEY DIFFERENCES • Adapter provides a different interface to its subject. Proxy provides the same interface. • Adapter is meant to change the interface of an existing object. 28
  • 29. BRIDGE PATTERN • The Bridge pattern is something you implement up front - if you know you have two orthogonal hierarchies, it provides a way to decouple the interface and the implementation in such a way that you don't get an insane number of classes. 29
  • 30. BRIDGE PATTERN • Let's say you have: 30
  • 32. KEY DIFFERENCES • Adapter makes things work after they're designed; Bridge makes them work before they are. • Bridge is designed up-front to let the abstraction and the implementation vary independently. Adapter is retrofitted to make unrelated classes work together. 32
  • 33. DIFFERENCE BETWEEN FACTORY PATTERN AND BUILDER PATTERN 33
  • 34. FACTORY PATTERN • The factory is in charge of creating various subtypes of an object depending on the needs. • The user of a factory method doesn't need to know the exact subtype of that object. An example of a factory method createCar might return a Ford or a Honda typed object. 34
  • 36. BUILDER PATTERN • In the Builder pattern, different subtypes are also created by a builder method, but the composition of the objects might differ within the same subclass. • To continue the car example you might have a createCar builder method which creates a Honda typed object with a 4 cylinder engine, or a Honda typed object with 6 cylinders. The builder pattern allows for this finer granularity. 36