r/PHPhelp • • Nov 26 '19

Should I learn design patterns?

I've been learning/using php with frameworks like codeigniter, and wordpress, else just procedurally. I understand the syntax of OOP; classes, properties, access modifiers, and inheritance, but not really the any OOP design patterns (unless inheritance is counted).

Last week I got an interview for a trainee-ship and had to write a small amount of php (specifically) without a framework. First was to create a form that allows users to register their email address in MySQL. The other was to read an RSS feed and prepare JSON data to be fetched by JS on the front-end.

I kind of feel I needed to do this in OOP, but wasn't really sure if I needed to use a certain design pattern. I ended up just doing it procedurally, but was wondering how the professionals would have implemented this.

So if you had this assignment, how would you have implemented it? The procedural way, simple OOP - like a class and an instance, or OOP with some design pattern?

Is it a really bad thing that I don't have a grasp of basic design patterns yet?

Thanks.

8 Upvotes

8 comments sorted by

View all comments

1

u/[deleted] Nov 26 '19

Kinda. I did a degree in CS so I had to learn them as part of the curriculum. It did help me understand some code a bit more (particularly any library that embraces them). I'll fully admit though that outside of an academic scenario, I've never coded anything using a design pattern.

As for your specific example - I'd probably have done it procedurally too. To me PHP just feels more "natural" used that way. I do a good amount of C# development too and fully embrace OOP there, but 99% of the time I don't bother in PHP.