SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Moose Design
                               Patterns
                Ynon Perek
                ynonperek@yahoo.com
                http://ynonperek.com




Tuesday, February 28, 2012
Good Code   Bad Code




Tuesday, February 28, 2012
OOP Use Cases

                    • Write code that other developers
                             will use
                    • Write code that will survive in an ever
                             changing environment




Tuesday, February 28, 2012
Meet The Moose
Tuesday, February 28, 2012
Moose

                    • Post Modern Object Oriented Perl
                    • Consistent OO Framework
                    • Stable


Tuesday, February 28, 2012
A First Class
                                                                                Class Def
                                                         package Person;


                    •
                                                         use Moose;
                             A class is just a package
                                                         has 'name', is => 'ro', isa => 'Str';
                                                         has 'age', is => 'rw', isa => 'Int';

                    •        A method is just a sub

                    •        An attribute is ...
                                                                                Class Use
                             We’ll get to that later     package main;
                                                         use feature ':5.10';

                                                         my $p = Person->new(name => "James");
                                                         say $p->name;




Tuesday, February 28, 2012
Object Methods
           package Car;
           use Moose;

           has 'speed', is => 'ro';              •   A method takes
                                                     the object
           sub go {
               my $self = shift;                     (invocant) as its
               print   "Vroom Vroom [speed: ",       first argument
                       $self->speed,
                       "]n";
           }
                                                 •   That’s why we use
           package main;                             my $self = shift
           my $c = Car->new(speed => 10);
           $c->go;




Tuesday, February 28, 2012
Whats In The Box


            •      A new method

            •      use strict, use warnings

            •      Type Validation

            •      Organize Your Code




Tuesday, February 28, 2012
OO Design
Tuesday, February 28, 2012
OO Design
                   Patterns
               Tested, Proven development
                paradigms for speeding up
                  development process




Tuesday, February 28, 2012
Pattern Structure

                    • Name
                    • Problem
                    • Solution
                    • Consequences

Tuesday, February 28, 2012
Categories
           Creational          Behavioral    Structural

            Singleton         Observer      Mixins
                              Template
            Factory
                              Method        Composite
             Builder
                               Flyweight



Tuesday, February 28, 2012
Creational Patterns
                    • Abstract instantiation process
                    • We must only create one log file instance
                             for the entire system
                    • An XML tree is built gradually,
                             node-by-node




Tuesday, February 28, 2012
Singleton Pattern

                    • Ensure a class only has one instance
                    • Manage Resource Sharing


Tuesday, February 28, 2012
Moose Singleton
           package Logger;
           use MooseX::Singleton;

           sub debug { ... }
           sub warn { ... }

           package main;

           my $logger         = Logger->instance;
           my $same           = Logger->instance;

           my $and_again      = Logger->new;

           $logger->debug("Hello World");




Tuesday, February 28, 2012
Factory
                    • Create a different object based
                             on some conditional
                    • Treat the newly created objects
                             the same way
                    • Practical: abstract away OS related code

Tuesday, February 28, 2012
Factory
           package AppConfig;
           use Moose::Role;

           requires 'debug_mode';          •   Use a Role to
           requires 'native_separators';
                                               specify common
           requires 'root_fs';                 behavior




Tuesday, February 28, 2012
Factory
     package ConfigFactory;
     use Moose;

     sub build_config {
         my $cfg;                                    •   All creation logic
         given ($^O) {                                   stays in the
             $cfg = WinConfig->new when /MSWin32/;
             $cfg = UnixConfig->new;
                                                         factory
         }
         return $cfg;
     }




Tuesday, February 28, 2012
Factory

         package main;                            •   Users only need
                                                      to know about
         my $cfg = ConfigFactory->build_config;
                                                      the role, not the
         say $cfg->debug_mode;                        various
                                                      implementations




Tuesday, February 28, 2012
Creational Patterns




Tuesday, February 28, 2012
Behavioral Patterns

                    • Assignment of responsibility
                             between objects and classes
                    • Use either inheritance or composition


Tuesday, February 28, 2012
Template Methods
Tuesday, February 28, 2012
Template Method

                    • Separate the algorithm from the actual
                             implementation
                    • Define the skeleton of an algorithm
                    • Example: Paint on a canvas or printer


Tuesday, February 28, 2012
Painter Example
                                Draw Pixel




Tuesday, February 28, 2012
Roles: Partials
                                                       package Painter;

                    •        Template methods are      use Moose::Role;

                             implemented using roles   requires 'drawPixel';


                    •        Use requires to define a   sub draw_line      { ... }
                                                       sub draw_triangle { ... }
                             partial implementation    sub draw_rectangle { ... }




Tuesday, February 28, 2012
Roles: Partials
                  package ScreenPainter;
                  use Moose;

                  with 'Painter';

                  sub draw_pixel { ... }

                  package main;
                  my $painter = ScreenPainter->new;

                  $painter->draw_line(0, 0, 100, 100);




Tuesday, February 28, 2012
Behavioral Patterns




Tuesday, February 28, 2012
Structural

                    • Control structure of an object
                    • Is it composed of other objects ?
                    • How are these parts used ?
                    • Composition, Decorator, Adapter

Tuesday, February 28, 2012
Composition: What

                 Send Mail                  Send Mail
                                  Contact               Email
               Call
                                                 Call

                                                        Phone




Tuesday, February 28, 2012
Moose Composition

                    • Moose has a built-in support for delegation
                    • Use handles on an attribute to create an
                             effective composition
                    • Prefer composition over inheritance


Tuesday, February 28, 2012
Delegation: How
                                                    package Contact;

                  •     Can take regular            use Moose;

                        expressions                 has 'email' => (
                                                        is      => 'ro',
                  •     Can take hashref                handles => [ qw/send_mail/ ]
                                                    );

                  •     perldoc
                        Moose::Manual::Delegation   my $c = Contact->new;
                                                    $c->send_mail(subject => "Hello",
                                                                  text => "...");




Tuesday, February 28, 2012
Delegation

                    • Delegation is explicit
                    • Performed via attributes
                    • Highly recommended


Tuesday, February 28, 2012
OO Design
           Consider design patterns

           Use the power of perl

           Clean Code is worth it




Tuesday, February 28, 2012
Thanks For
                              Listening
                Ynon Perek
                ynonperek@yahoo.com
                http://ynonperek.com




Tuesday, February 28, 2012

Contenu connexe

Tendances

Endpoint Security Solutions
Endpoint Security SolutionsEndpoint Security Solutions
Endpoint Security SolutionsThe TNS Group
 
Secure Software Development Lifecycle
Secure Software Development LifecycleSecure Software Development Lifecycle
Secure Software Development Lifecycle1&1
 
Brute force attack
Brute force attackBrute force attack
Brute force attackjoycruiser
 
IT Security Awarenesss by Northern Virginia Community College
IT Security Awarenesss by Northern Virginia Community CollegeIT Security Awarenesss by Northern Virginia Community College
IT Security Awarenesss by Northern Virginia Community CollegeAtlantic Training, LLC.
 
Nist 800 82 ICS Security Auditing Framework
Nist 800 82 ICS Security Auditing FrameworkNist 800 82 ICS Security Auditing Framework
Nist 800 82 ICS Security Auditing FrameworkMarcoAfzali
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Bernardo Damele A. G.
 
Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...
Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...
Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...Alcyon Ferreira de Souza Junior, MSc
 
DerbyCon 7 - Hacking VDI, Recon and Attack Methods
DerbyCon 7 - Hacking VDI, Recon and Attack MethodsDerbyCon 7 - Hacking VDI, Recon and Attack Methods
DerbyCon 7 - Hacking VDI, Recon and Attack MethodsPatrick Coble
 
Role based access control
Role based access controlRole based access control
Role based access controlPeter Edwards
 
Authentication Technologies
Authentication TechnologiesAuthentication Technologies
Authentication TechnologiesNicholas Davis
 
Module 8 System Hacking
Module 8   System HackingModule 8   System Hacking
Module 8 System Hackingleminhvuong
 
Password Attacks.pdf
Password Attacks.pdfPassword Attacks.pdf
Password Attacks.pdfAndy32903
 

Tendances (20)

Endpoint Security Solutions
Endpoint Security SolutionsEndpoint Security Solutions
Endpoint Security Solutions
 
Secure Software Development Lifecycle
Secure Software Development LifecycleSecure Software Development Lifecycle
Secure Software Development Lifecycle
 
Brute force attack
Brute force attackBrute force attack
Brute force attack
 
SC-900 Intro
SC-900 IntroSC-900 Intro
SC-900 Intro
 
IT Security Awarenesss by Northern Virginia Community College
IT Security Awarenesss by Northern Virginia Community CollegeIT Security Awarenesss by Northern Virginia Community College
IT Security Awarenesss by Northern Virginia Community College
 
Ace Up the Sleeve
Ace Up the SleeveAce Up the Sleeve
Ace Up the Sleeve
 
Nist 800 82 ICS Security Auditing Framework
Nist 800 82 ICS Security Auditing FrameworkNist 800 82 ICS Security Auditing Framework
Nist 800 82 ICS Security Auditing Framework
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
 
Password management
Password managementPassword management
Password management
 
Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...
Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...
Aula 01 - Curso GRATUITO EAD de Desenvolvimento Seguro de Software com Alcyon...
 
DerbyCon 7 - Hacking VDI, Recon and Attack Methods
DerbyCon 7 - Hacking VDI, Recon and Attack MethodsDerbyCon 7 - Hacking VDI, Recon and Attack Methods
DerbyCon 7 - Hacking VDI, Recon and Attack Methods
 
Computer Security
Computer SecurityComputer Security
Computer Security
 
Endpoint Security
Endpoint SecurityEndpoint Security
Endpoint Security
 
Introduction XSS
Introduction XSSIntroduction XSS
Introduction XSS
 
Role based access control
Role based access controlRole based access control
Role based access control
 
Zero Trust
Zero TrustZero Trust
Zero Trust
 
Authentication Technologies
Authentication TechnologiesAuthentication Technologies
Authentication Technologies
 
Module 8 System Hacking
Module 8   System HackingModule 8   System Hacking
Module 8 System Hacking
 
Password Attacks.pdf
Password Attacks.pdfPassword Attacks.pdf
Password Attacks.pdf
 
Building Your Roadmap Sucessful Identity And Access Management
Building Your Roadmap Sucessful Identity And Access ManagementBuilding Your Roadmap Sucessful Identity And Access Management
Building Your Roadmap Sucessful Identity And Access Management
 

Similaire à Moose Design Patterns

Flexible heterogenous replication
Flexible heterogenous replicationFlexible heterogenous replication
Flexible heterogenous replicationJeff Mace
 
Engines Lightning Talk
Engines Lightning TalkEngines Lightning Talk
Engines Lightning TalkDan Pickett
 
Mansoura University CSED & Nozom web development sprint
Mansoura University CSED & Nozom web development sprintMansoura University CSED & Nozom web development sprint
Mansoura University CSED & Nozom web development sprintAl Sayed Gamal
 
Disconnecting the Database with ActiveRecord
Disconnecting the Database with ActiveRecordDisconnecting the Database with ActiveRecord
Disconnecting the Database with ActiveRecordBen Mabey
 
Overview of Backbone
Overview of BackboneOverview of Backbone
Overview of BackboneJohn Ashmead
 
7th math c2 -l28--nov6
7th math c2 -l28--nov67th math c2 -l28--nov6
7th math c2 -l28--nov6jdurst65
 
Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2
Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2
Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2Jeffrey Breen
 
Getting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit testGetting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit testMichele Capra
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Max Klymyshyn
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScriptYnon Perek
 
Socal piggies-app-deploy
Socal piggies-app-deploySocal piggies-app-deploy
Socal piggies-app-deployjtimberman
 
The state of drupal 8 - Drupalcamp Gent
The state of drupal 8  - Drupalcamp GentThe state of drupal 8  - Drupalcamp Gent
The state of drupal 8 - Drupalcamp Gentswentel
 
developing sysadmin, sysadmining developersGuug devops puppet
developing sysadmin, sysadmining developersGuug devops puppetdeveloping sysadmin, sysadmining developersGuug devops puppet
developing sysadmin, sysadmining developersGuug devops puppetMartin Alfke
 
Como escalar aplicações PHP
Como escalar aplicações PHPComo escalar aplicações PHP
Como escalar aplicações PHPAugusto Pascutti
 
Eero cocoaheadssf-talk
Eero cocoaheadssf-talkEero cocoaheadssf-talk
Eero cocoaheadssf-talkAndy Arvanitis
 

Similaire à Moose Design Patterns (18)

Flexible heterogenous replication
Flexible heterogenous replicationFlexible heterogenous replication
Flexible heterogenous replication
 
Engines Lightning Talk
Engines Lightning TalkEngines Lightning Talk
Engines Lightning Talk
 
Mansoura University CSED & Nozom web development sprint
Mansoura University CSED & Nozom web development sprintMansoura University CSED & Nozom web development sprint
Mansoura University CSED & Nozom web development sprint
 
Brubeck: Overview
Brubeck: OverviewBrubeck: Overview
Brubeck: Overview
 
Disconnecting the Database with ActiveRecord
Disconnecting the Database with ActiveRecordDisconnecting the Database with ActiveRecord
Disconnecting the Database with ActiveRecord
 
Overview of Backbone
Overview of BackboneOverview of Backbone
Overview of Backbone
 
Brief overview of NoSQL & MongoDB for GTUG Tbilisi Event
Brief overview of NoSQL & MongoDB for GTUG Tbilisi EventBrief overview of NoSQL & MongoDB for GTUG Tbilisi Event
Brief overview of NoSQL & MongoDB for GTUG Tbilisi Event
 
7th math c2 -l28--nov6
7th math c2 -l28--nov67th math c2 -l28--nov6
7th math c2 -l28--nov6
 
Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2
Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2
Big Data Step-by-Step: Infrastructure 2/3: Running R and RStudio on EC2
 
Getting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit testGetting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit test
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
 
Socal piggies-app-deploy
Socal piggies-app-deploySocal piggies-app-deploy
Socal piggies-app-deploy
 
The state of drupal 8 - Drupalcamp Gent
The state of drupal 8  - Drupalcamp GentThe state of drupal 8  - Drupalcamp Gent
The state of drupal 8 - Drupalcamp Gent
 
developing sysadmin, sysadmining developersGuug devops puppet
developing sysadmin, sysadmining developersGuug devops puppetdeveloping sysadmin, sysadmining developersGuug devops puppet
developing sysadmin, sysadmining developersGuug devops puppet
 
D7 as D8
D7 as D8D7 as D8
D7 as D8
 
Como escalar aplicações PHP
Como escalar aplicações PHPComo escalar aplicações PHP
Como escalar aplicações PHP
 
Eero cocoaheadssf-talk
Eero cocoaheadssf-talkEero cocoaheadssf-talk
Eero cocoaheadssf-talk
 

Plus de Ynon Perek

09 performance
09 performance09 performance
09 performanceYnon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web IntroYnon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile DevicesYnon Perek
 
Architecture app
Architecture appArchitecture app
Architecture appYnon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsYnon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScriptYnon Perek
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application TestingYnon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application SecurityYnon Perek
 

Plus de Ynon Perek (20)

Regexp
RegexpRegexp
Regexp
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
09 performance
09 performance09 performance
09 performance
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Vimperl
VimperlVimperl
Vimperl
 
Syllabus
SyllabusSyllabus
Syllabus
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
 
Network
NetworkNetwork
Network
 
Architecture app
Architecture appArchitecture app
Architecture app
 
Cryptography
CryptographyCryptography
Cryptography
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
 
Accessibility
AccessibilityAccessibility
Accessibility
 
Angularjs
AngularjsAngularjs
Angularjs
 
Js memory
Js memoryJs memory
Js memory
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

Moose Design Patterns

  • 1. Moose Design Patterns Ynon Perek ynonperek@yahoo.com http://ynonperek.com Tuesday, February 28, 2012
  • 2. Good Code Bad Code Tuesday, February 28, 2012
  • 3. OOP Use Cases • Write code that other developers will use • Write code that will survive in an ever changing environment Tuesday, February 28, 2012
  • 4. Meet The Moose Tuesday, February 28, 2012
  • 5. Moose • Post Modern Object Oriented Perl • Consistent OO Framework • Stable Tuesday, February 28, 2012
  • 6. A First Class Class Def package Person; • use Moose; A class is just a package has 'name', is => 'ro', isa => 'Str'; has 'age', is => 'rw', isa => 'Int'; • A method is just a sub • An attribute is ... Class Use We’ll get to that later package main; use feature ':5.10'; my $p = Person->new(name => "James"); say $p->name; Tuesday, February 28, 2012
  • 7. Object Methods package Car; use Moose; has 'speed', is => 'ro'; • A method takes the object sub go {     my $self = shift; (invocant) as its     print "Vroom Vroom [speed: ", first argument             $self->speed,             "]n"; } • That’s why we use package main; my $self = shift my $c = Car->new(speed => 10); $c->go; Tuesday, February 28, 2012
  • 8. Whats In The Box • A new method • use strict, use warnings • Type Validation • Organize Your Code Tuesday, February 28, 2012
  • 10. OO Design Patterns Tested, Proven development paradigms for speeding up development process Tuesday, February 28, 2012
  • 11. Pattern Structure • Name • Problem • Solution • Consequences Tuesday, February 28, 2012
  • 12. Categories Creational Behavioral Structural Singleton Observer Mixins Template Factory Method Composite Builder Flyweight Tuesday, February 28, 2012
  • 13. Creational Patterns • Abstract instantiation process • We must only create one log file instance for the entire system • An XML tree is built gradually, node-by-node Tuesday, February 28, 2012
  • 14. Singleton Pattern • Ensure a class only has one instance • Manage Resource Sharing Tuesday, February 28, 2012
  • 15. Moose Singleton package Logger; use MooseX::Singleton; sub debug { ... } sub warn { ... } package main; my $logger = Logger->instance; my $same = Logger->instance; my $and_again = Logger->new; $logger->debug("Hello World"); Tuesday, February 28, 2012
  • 16. Factory • Create a different object based on some conditional • Treat the newly created objects the same way • Practical: abstract away OS related code Tuesday, February 28, 2012
  • 17. Factory package AppConfig; use Moose::Role; requires 'debug_mode'; • Use a Role to requires 'native_separators'; specify common requires 'root_fs'; behavior Tuesday, February 28, 2012
  • 18. Factory package ConfigFactory; use Moose; sub build_config {     my $cfg; • All creation logic     given ($^O) { stays in the         $cfg = WinConfig->new when /MSWin32/;         $cfg = UnixConfig->new; factory     }     return $cfg; } Tuesday, February 28, 2012
  • 19. Factory package main; • Users only need to know about my $cfg = ConfigFactory->build_config; the role, not the say $cfg->debug_mode; various implementations Tuesday, February 28, 2012
  • 21. Behavioral Patterns • Assignment of responsibility between objects and classes • Use either inheritance or composition Tuesday, February 28, 2012
  • 23. Template Method • Separate the algorithm from the actual implementation • Define the skeleton of an algorithm • Example: Paint on a canvas or printer Tuesday, February 28, 2012
  • 24. Painter Example Draw Pixel Tuesday, February 28, 2012
  • 25. Roles: Partials package Painter; • Template methods are use Moose::Role; implemented using roles requires 'drawPixel'; • Use requires to define a sub draw_line { ... } sub draw_triangle { ... } partial implementation sub draw_rectangle { ... } Tuesday, February 28, 2012
  • 26. Roles: Partials package ScreenPainter; use Moose; with 'Painter'; sub draw_pixel { ... } package main; my $painter = ScreenPainter->new; $painter->draw_line(0, 0, 100, 100); Tuesday, February 28, 2012
  • 28. Structural • Control structure of an object • Is it composed of other objects ? • How are these parts used ? • Composition, Decorator, Adapter Tuesday, February 28, 2012
  • 29. Composition: What Send Mail Send Mail Contact Email Call Call Phone Tuesday, February 28, 2012
  • 30. Moose Composition • Moose has a built-in support for delegation • Use handles on an attribute to create an effective composition • Prefer composition over inheritance Tuesday, February 28, 2012
  • 31. Delegation: How package Contact; • Can take regular use Moose; expressions has 'email' => (     is => 'ro', • Can take hashref     handles => [ qw/send_mail/ ] ); • perldoc Moose::Manual::Delegation my $c = Contact->new; $c->send_mail(subject => "Hello",               text => "..."); Tuesday, February 28, 2012
  • 32. Delegation • Delegation is explicit • Performed via attributes • Highly recommended Tuesday, February 28, 2012
  • 33. OO Design Consider design patterns Use the power of perl Clean Code is worth it Tuesday, February 28, 2012
  • 34. Thanks For Listening Ynon Perek ynonperek@yahoo.com http://ynonperek.com Tuesday, February 28, 2012