Resources for OOP implementations

Hello,

I’m working on a project that has a lot of legacy code implemented using PHP. I’d like to start transitioning them to a framework but I think the first step is to start building new tools using OOP and then refactor other portions of the app slowly over time. I’m having two issues that I hope you all could help shed some light on.

First I’m not quite sure what the best way to begin. How do I bridge the old code w/ the new OOP code?

Second, I’ve done a million tutorials that talk about how an object is like a car or animal or whatever which was helpful for learning the concepts but what I’m really looking for now is a how to guide on building common elements of a web app using OOP. How to build a form and do validation etc etc using OOP. I’m just looking for some tutorials or guidance on how real world OOP implementations should look.

Ugh… I don’t envy you my friend. It sounds like you might still be trying to grasp a few ideas about what OOP is and how it works, then being tossed into the deep end with a system migration. I specialize in migrations and integrations and I can tell you that they can be challenging even for someone like me. You really have to understand three fundamental things…

  1. How does the legacy code work?
  2. Is it still needed?
  3. How to translate the concepts into the new framework

I often spend a few days to even a couple weeks running through the code base. I make several notes about what is actually there, the basic concepts, what should be kept or tossed and what is critical for a minimal viable product (MVP) in the new framework. Sometimes I test pieces of the code, sometimes I put in some extra debugging print lines, I look at all the output it creates and I ask lots and lots of questions to stakeholders and those who know the old system.

Once I have a grasp of what things are doing, what is working and what doesn’t, I start trimming. I will create a new project with the new framework and then piece by piece I will look to remove unused code, dead code, sometimes pages that are not even used anymore. The whole process here is to get the actual code base foot print as small as possible before converting it over. It is easier to translate 10 pages over than 20 pages where 10 are not even working or are useless.

After things have been trimmed down to basic working functionality, then it is a matter of looking at the code, referring to your notes from the first step and translating it into new code for the framework. Oh this function’s purpose is to send an email message? Ok, do I need this function or does the framework already provide a function for sending email messages? Things like that.

Obviously the translation bit is the majority of the work but only by a little. It is like 55% of the work. The other 45% is understanding the old code base, asking questions and figuring out what is going to actually be moved over.

So that is the answer I have for the first question of yours.

The second question is completely based on the framework you are moving to. How you structure your objects, code and what you use is going to be dictated by the framework. Some ideas might be similar but that is why you are moving to a framework to begin with… to follow their conventions, style and guidelines to produce reliable and predictable code that conforms to the framework. :slight_smile:

2 Likes

@Martyr2 This response was incredible! Thank you so much for taking the time to respond in such wonderful detail, this was very illuminating. I have a question about your response to part 2: I was thinking about trying to use a really minimal framework because my employer doesn’t necessarily want to be tied too strongly to an ecosystem. In that case a lot of the implementations would largely be from scratch. Do you have any guides or references that might be useful in that case? I’m currently studying design patterns, but I feel like what I’m learning is a bit too general for specific web app implementations and for me to get up and running properly. Starting out in OOP is challenging!!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.