advanced php concepts - tutorial 2 of 3
TRANSCRIPT
Advanced PHP ConceptsTutorial Two
Series Overview• Object-Oriented Programming• Introduction to Objects• Basic OOP Classes
• OOP Principles• MVC• SOLID• Namespaces
• Frameworks• Symfony 3
MVC• Model-View-Controller• This architecture has
become extremely popular for designing web applications.
MVC (cont.)• A controller can send commands to the model to
update the model's state (e.g., editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g., by scrolling through a document).• A model stores data that is retrieved according to
commands from the controller and displayed in the view.• A view generates an output presentation to the user
based on changes in the model.• A view controller generates an output view and an
embedded controller.
SOLID• Single responsibility principle
• A class should have only a single responsibility• Open/closed principle
• Software entities should be open for extension, but closed for modification• Liskov substitution principle
• Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program
• Interface segregation principle• Many client-specific interfaces are better than one general-purpose interface
• Dependency inversion principle• One should “Depend upon Abstractions. Do not depend upon concretions.”
Other OOP Principles• DRY (Don’t Repeat Yourself)• KISS (Keep It Simple, Stupid)
Namespaces• Namespaces are commonly structured as hierarchies
to allow reuse of names in different contexts.• In computer programming, namespaces are typically
employed for the purpose of grouping symbols and identifiers around a particular functionality and to avoid name collisions between multiple identifiers that share the same name.• A namespace is defined by the namespace keyword.
Why use namespaces?• Often when you are working on a very large project you will
encounter naming collisions between Classes.• Using namespaces solves this problem, as well as giving
your code better structure by grouping all Classes of the same module together in one namespace, organised by their purpose.• Examples:• AppBundle\Controller• AppBundle\Repository
• Let’s revisit our Examples project from the previous tutorial…
ExamplesBefore
After Refactoring
Summary• MVC – Model-View-Controller
• Model updates View User sees View User uses Controller Controller manipulates Model Model updates View
• SOLID Principles• Single responsibility principle• Open/closed principle• Liskov substitution principle• Interface segregation principle• Dependency inversion principle
• Namespaces• Using namespaces gives your code better structure by grouping all
Classes of the same module together in one namespace, organised by their purpose.
Examples available from:https://github.com/WhiteheadJ/Examples
Further Reading• http://martinfowler.com/eaaDev/uiArchs.html• https://en.wikipedia.org/wiki/Don%27t_repeat_yourself• https://en.wikipedia.org/wiki/KISS_principle
References• https://en.wikipedia.org/wiki/Model–view–controller• "MVC-Process" by RegisFrey - Own work. Licensed
under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:MVC-Process.svg#/media/File:MVC-Process.svg• https://en.wikipedia.org/wiki/SOLID_(object-oriented_d
esign)• https://en.wikipedia.org/wiki/Namespace