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/fingerofchicken Nov 26 '19

You should learn them. They're useful approaches to common problems. But you shouldn't try and shoehorn them into every situation.

I wouldn't worry about feeling like you "should" do OOP. OOP is a convention. It's good for some situations. It's not for others. But it's not inherently better at everything.