SlideShare une entreprise Scribd logo
1  sur  18
Perl Design Patterns
             brian d foy
   Stonehenge Consulting Ser vices
         February 24, 2006
     Grand Rapids Perl Mongers



               Sponsored by PriorityHealth
Patterns aren’t a ...
code cookbook
module on CPAN
methodology
goal
religion
Patterns are a ...
abstraction for things we need to do
solutions for common problems
name for a design element
common language for design discussions
way to apply a common design to code
relationships
Three parts

Context
System of forces
Solution
Nothing’s Free

Actions have reactions
Complexity turns up somewhere else
Choices have consequences
Who’s responsible?

Our application needs config information
But we have several modules
Who loads the data?
How do the other modules get it?
A pattern

Load the configuration from anywhere
But load it only one time
Anyone else gets a reference to it
The order doesn’t matter
What’s in a name

A couple words instead of sentences
We agree on what the name implies
Others know what we mean
“A rose is a rose is a rose”
The Singleton
There is only one configuration
Let’s call it a singleton
... or a highlander
We don’t have an implementation
Just a name with implied design elements
An implementation
package My::Config;

my $singleton = undef;

sub new {
   my $class = shift;

  return $singleton if defined $singleton;

  $singleton = bless {}, $class;
  }
A use
package My::Database;
use My::Config;

my $config = My::Config->new( ... );

package My::Network;
use My::Config;

my $config = My::Config->new( ... );
That isn’t the only way

 The pattern is not a prescription
 It’s an option
 Maybe another pattern works better.
A Meta Class
   Write a meta class that contains all of
   the object parts
   Objects talk to the meta class to
   communicate with the other parts
use My::Controller;

my $controller = My::Controller->new(...);

my $value = $controller->config->get( ... );
Delegates
package My::Controller;

sub new {
   my $class = shift;

   my $self = bless {}, $class;

   # weaken some of these circular refs
   @$self{ qw(_config _database _network ) } = (
      My::Config->new( controller => $self ),
      DBI->new( ... ),
      My::Socket->new( controller => $self ),
      );

   $self;
   }

sub config { $_[0]{_config} }
Some Perl Modules

Apache::DBI
Netscape::Bookmarks
CGI::Prototype
many things in Class::*, almost
Beware

Patterns are not code
No matter what the Gang of Four say
Class::* is code
Ergo, ...
Perl is Better

People like Patterns because they get code
C++, Java suck at some things (Iterators)
Perl doesn’t suck at the same things
Further Reading
The Perl Review (lots of articles (by me))
“Design Patterns Aren’t” by Mark Jason
Dominus
 http:/
      /perl.plover.com/yak/design/

Design Patterns - Erich Gamma, et al.
(Gang of Four)
Perl Design Patterns Wiki
 http:/
      /perldesignpatterns.com/

Contenu connexe

Tendances

Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++Guneesh Basundhra
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learninglearn Ruby in AMC Square learning
learn Ruby in AMC Square learningASIT Education
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
Clean code lecture part I
Clean code lecture part IClean code lecture part I
Clean code lecture part IJun Shimizu
 
Building an NLP DNN in 5 Minutes
Building an NLP DNN in 5 MinutesBuilding an NLP DNN in 5 Minutes
Building an NLP DNN in 5 MinutesJenny Midwinter
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - EncapsulationMichael Heron
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - EncapsulationMichael Heron
 
Object oriented programming concept- Saurabh Upadhyay
Object oriented programming concept- Saurabh UpadhyayObject oriented programming concept- Saurabh Upadhyay
Object oriented programming concept- Saurabh UpadhyaySaurabh Upadhyay
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation javaJayasankarPR2
 
JAVA Data Types - Part 1
JAVA Data Types - Part 1JAVA Data Types - Part 1
JAVA Data Types - Part 1Ashok Asn
 

Tendances (20)

Oops
OopsOops
Oops
 
Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
 
Characteristics of oop
Characteristics of oopCharacteristics of oop
Characteristics of oop
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learninglearn Ruby in AMC Square learning
learn Ruby in AMC Square learning
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Clean code lecture part I
Clean code lecture part IClean code lecture part I
Clean code lecture part I
 
Building an NLP DNN in 5 Minutes
Building an NLP DNN in 5 MinutesBuilding an NLP DNN in 5 Minutes
Building an NLP DNN in 5 Minutes
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - Encapsulation
 
encapsulation
encapsulationencapsulation
encapsulation
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - Encapsulation
 
Object oriented programming concept- Saurabh Upadhyay
Object oriented programming concept- Saurabh UpadhyayObject oriented programming concept- Saurabh Upadhyay
Object oriented programming concept- Saurabh Upadhyay
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation java
 
JAVA Data Types - Part 1
JAVA Data Types - Part 1JAVA Data Types - Part 1
JAVA Data Types - Part 1
 

En vedette

Stellar - Monitor Case Study
Stellar - Monitor Case StudyStellar - Monitor Case Study
Stellar - Monitor Case StudyBrittany Hadfield
 
Service design & BE London 2016
Service design & BE London 2016Service design & BE London 2016
Service design & BE London 2016Luis Arnal
 
función de un plan de negocios
 función de un plan de negocios función de un plan de negocios
función de un plan de negociosLuis Camacho
 
TOPOLOGIAS DE RED
TOPOLOGIAS DE RED TOPOLOGIAS DE RED
TOPOLOGIAS DE RED fer-1399
 
Capability Document Experiential Recursive Simulation
Capability Document Experiential  Recursive SimulationCapability Document Experiential  Recursive Simulation
Capability Document Experiential Recursive Simulationkarthikeyan j
 
PO 397 Intro Political Machines
PO 397 Intro Political Machines PO 397 Intro Political Machines
PO 397 Intro Political Machines atrantham
 
Campaigns and Elections
Campaigns and ElectionsCampaigns and Elections
Campaigns and Electionsatrantham
 
Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)
Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)
Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)fernanda lopez
 
Pruebas de aislamiento motores baja tension
Pruebas de aislamiento motores baja tensionPruebas de aislamiento motores baja tension
Pruebas de aislamiento motores baja tensionGustavo De Haro
 
Module 1 lesson 4 identifying proportional relationships
Module 1 lesson 4 identifying proportional relationshipsModule 1 lesson 4 identifying proportional relationships
Module 1 lesson 4 identifying proportional relationshipsErik Tjersland
 
Project Management with Kanban 2.0
Project Management with Kanban 2.0Project Management with Kanban 2.0
Project Management with Kanban 2.0Planview
 
Why Marketing and IT Will Love the New DNN
Why Marketing and IT Will Love the New DNNWhy Marketing and IT Will Love the New DNN
Why Marketing and IT Will Love the New DNNDNN
 

En vedette (17)

Stellar - Monitor Case Study
Stellar - Monitor Case StudyStellar - Monitor Case Study
Stellar - Monitor Case Study
 
PO 101 Constitution
PO 101 ConstitutionPO 101 Constitution
PO 101 Constitution
 
Emprendedor
EmprendedorEmprendedor
Emprendedor
 
Service design & BE London 2016
Service design & BE London 2016Service design & BE London 2016
Service design & BE London 2016
 
función de un plan de negocios
 función de un plan de negocios función de un plan de negocios
función de un plan de negocios
 
TOPOLOGIAS DE RED
TOPOLOGIAS DE RED TOPOLOGIAS DE RED
TOPOLOGIAS DE RED
 
Capability Document Experiential Recursive Simulation
Capability Document Experiential  Recursive SimulationCapability Document Experiential  Recursive Simulation
Capability Document Experiential Recursive Simulation
 
PO 397 Intro Political Machines
PO 397 Intro Political Machines PO 397 Intro Political Machines
PO 397 Intro Political Machines
 
Campaigns and Elections
Campaigns and ElectionsCampaigns and Elections
Campaigns and Elections
 
CSC ADS Brochure
CSC ADS BrochureCSC ADS Brochure
CSC ADS Brochure
 
Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)
Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)
Las 10 carreras más estudiadas vs las 10 más demandadas por las empresas (1)
 
Tombolo
TomboloTombolo
Tombolo
 
Pruebas de aislamiento motores baja tension
Pruebas de aislamiento motores baja tensionPruebas de aislamiento motores baja tension
Pruebas de aislamiento motores baja tension
 
Module 1 lesson 4 identifying proportional relationships
Module 1 lesson 4 identifying proportional relationshipsModule 1 lesson 4 identifying proportional relationships
Module 1 lesson 4 identifying proportional relationships
 
Ppt manajemen pendidikan kelompok 1 fiks
Ppt manajemen pendidikan kelompok 1 fiksPpt manajemen pendidikan kelompok 1 fiks
Ppt manajemen pendidikan kelompok 1 fiks
 
Project Management with Kanban 2.0
Project Management with Kanban 2.0Project Management with Kanban 2.0
Project Management with Kanban 2.0
 
Why Marketing and IT Will Love the New DNN
Why Marketing and IT Will Love the New DNNWhy Marketing and IT Will Love the New DNN
Why Marketing and IT Will Love the New DNN
 

Similaire à Design Patterns in Perl (Grand Rapids Perl Mongers, 2006)

JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01Tekblink Jeeten
 
Object-Oriented Programming.pptx
Object-Oriented Programming.pptxObject-Oriented Programming.pptx
Object-Oriented Programming.pptxssusereae59d
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Nilesh Jayanandana
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixNovita Sari
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play NiceAlex Gaynor
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technologyfntsofttech
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringEyob Lube
 

Similaire à Design Patterns in Perl (Grand Rapids Perl Mongers, 2006) (20)

JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Adventures in TclOO
Adventures in TclOOAdventures in TclOO
Adventures in TclOO
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01
Top 100-php-interview-questions-and-answers-are-below-120816023558-phpapp01
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
Object-Oriented Programming.pptx
Object-Oriented Programming.pptxObject-Oriented Programming.pptx
Object-Oriented Programming.pptx
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/Unix
 
C# interview
C# interviewC# interview
C# interview
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play Nice
 
Value Objects
Value ObjectsValue Objects
Value Objects
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Warehousing
WarehousingWarehousing
Warehousing
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
Only oop
Only oopOnly oop
Only oop
 

Plus de brian d foy

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentationbrian d foy
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perlbrian d foy
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)brian d foy
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)brian d foy
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)brian d foy
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)brian d foy
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6brian d foy
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6brian d foy
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new featuresbrian d foy
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transformbrian d foy
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6brian d foy
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Communitybrian d foy
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014brian d foy
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPANbrian d foy
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trialbrian d foy
 

Plus de brian d foy (20)

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentation
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perl
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transform
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
I ❤ CPAN
I ❤ CPANI ❤ CPAN
I ❤ CPAN
 

Dernier

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Dernier (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Design Patterns in Perl (Grand Rapids Perl Mongers, 2006)

  • 1. Perl Design Patterns brian d foy Stonehenge Consulting Ser vices February 24, 2006 Grand Rapids Perl Mongers Sponsored by PriorityHealth
  • 2. Patterns aren’t a ... code cookbook module on CPAN methodology goal religion
  • 3. Patterns are a ... abstraction for things we need to do solutions for common problems name for a design element common language for design discussions way to apply a common design to code relationships
  • 5. Nothing’s Free Actions have reactions Complexity turns up somewhere else Choices have consequences
  • 6. Who’s responsible? Our application needs config information But we have several modules Who loads the data? How do the other modules get it?
  • 7. A pattern Load the configuration from anywhere But load it only one time Anyone else gets a reference to it The order doesn’t matter
  • 8. What’s in a name A couple words instead of sentences We agree on what the name implies Others know what we mean “A rose is a rose is a rose”
  • 9. The Singleton There is only one configuration Let’s call it a singleton ... or a highlander We don’t have an implementation Just a name with implied design elements
  • 10. An implementation package My::Config; my $singleton = undef; sub new { my $class = shift; return $singleton if defined $singleton; $singleton = bless {}, $class; }
  • 11. A use package My::Database; use My::Config; my $config = My::Config->new( ... ); package My::Network; use My::Config; my $config = My::Config->new( ... );
  • 12. That isn’t the only way The pattern is not a prescription It’s an option Maybe another pattern works better.
  • 13. A Meta Class Write a meta class that contains all of the object parts Objects talk to the meta class to communicate with the other parts use My::Controller; my $controller = My::Controller->new(...); my $value = $controller->config->get( ... );
  • 14. Delegates package My::Controller; sub new { my $class = shift; my $self = bless {}, $class; # weaken some of these circular refs @$self{ qw(_config _database _network ) } = ( My::Config->new( controller => $self ), DBI->new( ... ), My::Socket->new( controller => $self ), ); $self; } sub config { $_[0]{_config} }
  • 16. Beware Patterns are not code No matter what the Gang of Four say Class::* is code Ergo, ...
  • 17. Perl is Better People like Patterns because they get code C++, Java suck at some things (Iterators) Perl doesn’t suck at the same things
  • 18. Further Reading The Perl Review (lots of articles (by me)) “Design Patterns Aren’t” by Mark Jason Dominus http:/ /perl.plover.com/yak/design/ Design Patterns - Erich Gamma, et al. (Gang of Four) Perl Design Patterns Wiki http:/ /perldesignpatterns.com/