Refactoring.Guru : Design Patterns + PHP

Refactoring.Guru is a great resource for learning about refactoring best practices and design patterns. A lot of the website’s content is also available as Dive into Design Patterns ebook.

Today I came across this GitHub repository, which makes this resource even better specifically for PHP developers. Yup, that’s right, the GitHub repository features all code examples written in PHP 7.3, making it super easy to jump into coding.

And if you aren’t a PHP developer, have a look at the other repositories, which do the same for a few other programming languages.

ORM: Active Record vs. Data Mapper


Everybody building a web application with a modern framework, is already probably using an ORM (Object-Relational Mapping).  Most frameworks include one out of the box.  But digging deeper into the subject, ORMs do vary from each other, and some cases, very significantly.

Most variations are coming from two main approaches: Active Record and Data Mapper.  I’ve heard the terms for a long time, but today decided to look into the meaning and the actual difference.

The two approaches seem very similar.  The difference is described in a multitude of articles online.  I particularly liked this one.  In essence, Active Record is a better choice for simpler, CRUD-based applications.  Data Mapper, on the other hand, is better for domain-specific applications, as it provides another level of abstraction between the domain objects and the persistence layer.

Most of my work these days is done with CakePHP framework, which I now thought uses the Active Record pattern.  But it turns out that CakePHP ORM so powerful, because it’s more than just one of those:

The CakePHP ORM borrows ideas and concepts from both ActiveRecord and Datamapper patterns. It aims to create a hybrid implementation that combines aspects of both patterns to create a fast, simple to use ORM.

It looks like I need to do some learning and dig deeper into the subject.  Pointers are welcome.

money – PHP library to make working with money safer, easier, and fun


money is a PHP library that implements Martin Fowler’s design pattern for money.  See the official documentation and this blog post for more information.

Some of the issues addresses by this library are the binding of the money amount to the currency, and currency conversion operations.  If your code needs to deal with multiple currencies, you’ll definitely benefit from this library.  But even if you are dealing with a single currency, it’s still pretty handy, making the code more transparent and future proof.

Microservices Architecture : Best Practices


The other day I came across this article: “Microservices Architecture: All the Best Practices You Need to Know“.  There’s been a lot said and written about the microservices architectures around the web.  But I like this article in particular, because it paints a more realistic picture, in my opinion.  Big parts of it are covering the “why?” part of the whole conversation, and it presents a balanced view of pros and cons, as well as several approaches to solving the problems.

This is very refreshing after tonnes of “Microservices are amazing, and are the best thing since sliced bread” and “Microservices is nothing but hype and bubble” coverage out there.

Source Making : Design Patterns


Source Making does an excellent job with a few subjects.  The one I found particularly useful over the last couple of days is Design Patterns.  Not only the explanations are simple and straight to the point, and with a handy example, but they also clarify the differences between a pattern in question and a few similar patterns.