SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Destacado

Destacado (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
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Último (20)

Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 

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

Notas del editor

  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