Jump to content

Design patterns and keeping you code clean


Recommended Posts

In PHP I code mainly procedural, and I don't remember to have ever used a design pattern. However I use PHP only for my hobbies since a couple of years.

At work I use C# / .NET and there I code exclusively in OO, with a lot of design pattern usages: singleton, object pool, factory, injection, observer, composite, command pattern are the one I use more frequently. However you may very well code without knowing them, and actually implement one of those pattern without actually knowing it. Why? Because some are so generic like the composite pattern that you may end up using it by chance.

For your messy code, this is usually due to an initial design which didn't took in account all the needs, and / or is not flexible enough to change over time. However as the project grows / take ages, it's good practice to re-think it and restart from scratch. How often depends on your code, and project, some projects could be rewritten nearly on each major release, or 2 releases or some other projects can survive 10 years or more.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...