SlideShare une entreprise Scribd logo
1  sur  16
Interfaces and Traits Go Together Like
Peas and Carrots
Chase Peeler - Northeast PHP - 8/23/2015
Chase Peeler
Northeast PHP
August 23, 2015
Agenda
• Introductions
• Bubba Gump restaurant
• Interfaces
• Traits
• But what about …?
• Questions
Chase Peeler - Northeast PHP - 8/23/2015
Introductions
• Started with PHP in 1999
• Used professionally since 2005
• Currently Senior Software Architect
I may not be a smart man, but I know what PHP is
Chase Peeler - Northeast PHP - 8/23/2015
Bubba Gump Restaurant
• No affiliation with “Bubba Gump Shrimp Company”
• System for preparing, cooking, and serving different types of shrimp
Chase Peeler - Northeast PHP - 8/23/2015
Time to look at code!
Chase Peeler - Northeast PHP - 8/23/2015
What was wrong?
Chase Peeler - Northeast PHP - 8/23/2015
• Not easy to scale
• Lots of duplicated code
Interfaces
• “Object interfaces allow you to create code which specifies which
methods a class must implement, without having to define how these
methods are handled.” (http://php.net/manual/en/language.oop5.interfaces.php)
• You can only define public methods
• Cannot provide any functionality
• Allows your code to treat ALL classes that implement the interface as
if they were the same
Chase Peeler - Northeast PHP - 8/23/2015
Time to look at more code!
Chase Peeler - Northeast PHP - 8/23/2015
Better, but not great
• Still a lot of repeated code
• Copy/paste is bad
Chase Peeler - Northeast PHP - 8/23/2015
Traits
• “Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling
a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and
classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins. A Trait is similar to a class,
but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional
inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring
inheritance.”(http://php.net/manual/en/language.oop5.traits.php)
• Compiler assisted copy/paste
• Cannot be instantiated on their own
• Shared Behaviors
Chase Peeler - Northeast PHP - 8/23/2015
To the code again!
Chase Peeler - Northeast PHP - 8/23/2015
What about abstract classes?
• Example was a bit contrived
• What if you are already inheriting from a parent class?
• Does all of that functionality really belong in a parent class?
• Hierarchy can get really complex, really fast.
Chase Peeler - Northeast PHP - 8/23/2015
Let’s look at the code, one more time
Chase Peeler - Northeast PHP - 8/23/2015
Summary
• Copy/paste is bad unless the compiler does it
• Traits can provide ways of defining default functionality for your interfaces
• Traits prevent the need for parent classes that are able to do too many
different things
Chase Peeler - Northeast PHP - 8/23/2015
Questions?
Chase Peeler - Northeast PHP - 8/23/2015
Chase Peeler - Northeast PHP - 8/23/2015
• https://github.com/chasepeeler/nephp2015
• https://joind.in/14741
• http://lanyrd.com/sdrbxc
• chasepeeler@gmail.com
• http://blog.chasepeeler.com
• http://thebravesblog.com
• @chasepeeler
• @thebravesblog
Contact info and what not

Contenu connexe

En vedette

Don't Fear the Regex - Northeast PHP 2015
Don't Fear the Regex - Northeast PHP 2015Don't Fear the Regex - Northeast PHP 2015
Don't Fear the Regex - Northeast PHP 2015Sandy Smith
 
An introduction to contianers and Docker for PHP developers
An introduction to contianers and Docker for PHP developersAn introduction to contianers and Docker for PHP developers
An introduction to contianers and Docker for PHP developersRobert McFrazier
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developersAdam Culp
 
Are you a good scout? - PHPNW15 Unconf
Are you a good scout? - PHPNW15 UnconfAre you a good scout? - PHPNW15 Unconf
Are you a good scout? - PHPNW15 Unconfphpboyscout
 
Does Your Code Measure Up?
Does Your Code Measure Up?Does Your Code Measure Up?
Does Your Code Measure Up?Adam Culp
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through ExamplesCiaranMcNulty
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101Adam Culp
 
Clean application development tutorial
Clean application development tutorialClean application development tutorial
Clean application development tutorialAdam Culp
 

En vedette (10)

Don't Fear the Regex - Northeast PHP 2015
Don't Fear the Regex - Northeast PHP 2015Don't Fear the Regex - Northeast PHP 2015
Don't Fear the Regex - Northeast PHP 2015
 
An introduction to contianers and Docker for PHP developers
An introduction to contianers and Docker for PHP developersAn introduction to contianers and Docker for PHP developers
An introduction to contianers and Docker for PHP developers
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Designing Micro Experiences
Designing Micro ExperiencesDesigning Micro Experiences
Designing Micro Experiences
 
Are you a good scout? - PHPNW15 Unconf
Are you a good scout? - PHPNW15 UnconfAre you a good scout? - PHPNW15 Unconf
Are you a good scout? - PHPNW15 Unconf
 
Does Your Code Measure Up?
Does Your Code Measure Up?Does Your Code Measure Up?
Does Your Code Measure Up?
 
TDD with PhpSpec
TDD with PhpSpecTDD with PhpSpec
TDD with PhpSpec
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 
Clean application development tutorial
Clean application development tutorialClean application development tutorial
Clean application development tutorial
 

Dernier

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 

Dernier (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 

Interfaces and traits go together like peas and carrots

  • 1. Interfaces and Traits Go Together Like Peas and Carrots Chase Peeler - Northeast PHP - 8/23/2015 Chase Peeler Northeast PHP August 23, 2015
  • 2. Agenda • Introductions • Bubba Gump restaurant • Interfaces • Traits • But what about …? • Questions Chase Peeler - Northeast PHP - 8/23/2015
  • 3. Introductions • Started with PHP in 1999 • Used professionally since 2005 • Currently Senior Software Architect I may not be a smart man, but I know what PHP is Chase Peeler - Northeast PHP - 8/23/2015
  • 4. Bubba Gump Restaurant • No affiliation with “Bubba Gump Shrimp Company” • System for preparing, cooking, and serving different types of shrimp Chase Peeler - Northeast PHP - 8/23/2015
  • 5. Time to look at code! Chase Peeler - Northeast PHP - 8/23/2015
  • 6. What was wrong? Chase Peeler - Northeast PHP - 8/23/2015 • Not easy to scale • Lots of duplicated code
  • 7. Interfaces • “Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.” (http://php.net/manual/en/language.oop5.interfaces.php) • You can only define public methods • Cannot provide any functionality • Allows your code to treat ALL classes that implement the interface as if they were the same Chase Peeler - Northeast PHP - 8/23/2015
  • 8. Time to look at more code! Chase Peeler - Northeast PHP - 8/23/2015
  • 9. Better, but not great • Still a lot of repeated code • Copy/paste is bad Chase Peeler - Northeast PHP - 8/23/2015
  • 10. Traits • “Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins. A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance.”(http://php.net/manual/en/language.oop5.traits.php) • Compiler assisted copy/paste • Cannot be instantiated on their own • Shared Behaviors Chase Peeler - Northeast PHP - 8/23/2015
  • 11. To the code again! Chase Peeler - Northeast PHP - 8/23/2015
  • 12. What about abstract classes? • Example was a bit contrived • What if you are already inheriting from a parent class? • Does all of that functionality really belong in a parent class? • Hierarchy can get really complex, really fast. Chase Peeler - Northeast PHP - 8/23/2015
  • 13. Let’s look at the code, one more time Chase Peeler - Northeast PHP - 8/23/2015
  • 14. Summary • Copy/paste is bad unless the compiler does it • Traits can provide ways of defining default functionality for your interfaces • Traits prevent the need for parent classes that are able to do too many different things Chase Peeler - Northeast PHP - 8/23/2015
  • 15. Questions? Chase Peeler - Northeast PHP - 8/23/2015
  • 16. Chase Peeler - Northeast PHP - 8/23/2015 • https://github.com/chasepeeler/nephp2015 • https://joind.in/14741 • http://lanyrd.com/sdrbxc • chasepeeler@gmail.com • http://blog.chasepeeler.com • http://thebravesblog.com • @chasepeeler • @thebravesblog Contact info and what not

Notes de l'éditeur

  1. ----- Meeting Notes (8/18/15 11:16) ----- Welcome...
  2. ----- Meeting Notes (8/18/15 11:10) ----- gggg
  3. ----- Meeting Notes (8/18/15 11:16) ----- Freshman year at GT - didn't learn it in any classes, but used it in some 3/4000 level course Graduated 2005, went to work for Endeavor Endeavor is not a software company Has internal webapp built in PHP - was 2-3 years old when I started Lot of spaghetti code.. I made it worse Knew it was wrong, but didn't know how to make it right Now, SSA - built a new framework from the ground up Just released a new interface, rest API backend, backbone+marionette frontend ----- Meeting Notes (8/18/15 11:20) ----- First time speaking - go easy on me
  4. ----- Meeting Notes (8/18/15 11:20) ----- Somewhat contrived, but fits within our theme and should make sense
  5. ----- Meeting Notes (8/18/15 11:20) ----- Pause for feedback
  6. ----- Meeting Notes (8/18/15 11:20) ----- Can be treated as a "type"
  7. ----- Meeting Notes (8/18/15 11:20) ----- Works very well when sharing common functionality across the application, even between unrelated modules and classes