Slide 1

Slide 1 text

OOP in Web Development with PHP Oliver Mensah

Slide 2

Slide 2 text

Oliver Mensah Software Developer, Technical Writer, Developer Community Enthusiast ● Currently a National Service Personnel at AgroInnova ● Guest Author at Auth0 ● Co-Organizer at Facebook Developer Circle: Accra LinkedIn: @OliverMensahDev Twitter: @OliverMensahDev GitHub: @OliverMensahDev

Slide 3

Slide 3 text

Overview of Web Development ❖ Creating dynamic web applications ➢ Access via browser ❖ Broad Divisions ➢ Frontend ■ JavaScript, HTML, CSS ➢ Backend ■ PHP, NodeJs, etc. ➢ Database Technologies ■ MySQL, MongoDB, etc.

Slide 4

Slide 4 text

Overview of PHP ❖ Open source general-purpose scripting language, usually used for web development ❖ Code executed on the server ❖ Can be embedded in HTML ❖ Compatible with many databases ❖ Cross platform ❖ Large community ❖ Popular ➢ Simple ➢ Efficient ➢ Secure ➢ Flexible ❖ PHP Standard Recommendations(PSRs)

Slide 5

Slide 5 text

PHP Fundamentals ❖ Variables, Arrays, Loops ❖ Functions and Conditionals ❖ working with databases ❖ using third party libraries Example: https://github.com/OMENSAH/AshMa rt/blob/master/shoes_Search.php

Slide 6

Slide 6 text

I think we can do better In terms of ❖ Code design and organization ❖ Which means ➢ ability to reuse & recycle code ➢ encapsulate ➢ easier to maintain and test

Slide 7

Slide 7 text

Overview of OOP ❖ Program in terms of objects ❖ OOP concepts ➢ Classes ➢ Objects ➢ Methods & properties ➢ Encapsulation and Access Modifiers ➢ Data abstraction ➢ Inheritance and composition ➢ Polymorphism ❖ Autoloading ❖ Dependency Injection ❖ Code organizational patterns ➢ MVC ➢ MVC Repository pattern

Slide 8

Slide 8 text

Classes, Objects, Methods & properties ❖ Basic building blocks of OOP ➢ classes ➢ objects ➢ methods ➢ properties

Slide 9

Slide 9 text

Encapsulation ❖ Mechanism to restrict access to data and methods of class ❖ Achieved with access modifiers ➢ public ➢ protected ➢ private

Slide 10

Slide 10 text

Data abstraction ❖ Abstraction is a means of hiding details in order to simplify an interface

Slide 11

Slide 11 text

Inheritance and composition ❖ Code Reuse ➢ Use Composition when one class cannot exist without the other ➢ If a class wants to use a class functionality https://www.thepolyglotdeveloper.com/2018/09/inherita nce-composition-php-application/

Slide 12

Slide 12 text

Polymorphism ❖ Polymorphism says that methods in different classes that do similar things should have the same name. ❖ Achieved through ➢ Interface ➢ abstract class

Slide 13

Slide 13 text

Autoloading ❖ Autoloading classes from file path ❖ Reducing boilerplate codes

Slide 14

Slide 14 text

Chaining methods ❖ Continuous calling of method on object ❖ Method must return this

Slide 15

Slide 15 text

Dependency Injection ❖ Supplying the dependencies an object news ➢ Constructor injection ➢ Setter injection

Slide 16

Slide 16 text

Code Organizational Patterns ❖ MVC ➢ Model ➢ View ➢ Controller ❖ MVC- Repository Pattern ➢ Outsource data source operations from the controller http://bit.ly/MVCRepository http://bit.ly/mvc-pattern

Slide 17

Slide 17 text

DEMO

Slide 18

Slide 18 text

Proper MVC ❖ Friendly URL ➢ /farmers ➢ /farmers/7 ❖ Structure ➢ URL Rewriting ➢ Bootstrap ➢ Service Locators ❖ Many more

Slide 19

Slide 19 text

Questions?

Slide 20

Slide 20 text

RESOURCES: ● https://phptherightway.com/ ● https://phpenthusiast.com/ ● https://dev.to/omensah/basics-of-object-design-serie s-28ol ● https://www.thepolyglotdeveloper.com/2018/09/inhe ritance-composition-php-application/

Slide 21

Slide 21 text

“Explore the software world by sharing your learnings and experiences” Oliver Mensah