Quantcast
Channel: Comments on: Building Your Own URL Shortener
Viewing all articles
Browse latest Browse all 42

By: Alex Gervasio

$
0
0

Hey Alex,
Maybe I getting a little bit late to the party, but I have to say I really enjoyed the article. Concise, clear and straight to the point, so great work indeed. Just as a humble contribution, and assuming you don’t mind, here’re some improvements you may want considering to add to your nifty URL shortener:
1) Get rid of the static fields, ASAP. In the past we’ve all been avid consumers of static properties, specially with Singletons, (not to mention those mutable, horrifying static methods). But OOP is about interconnecting objects where each one carries a different state. So using static members doesn’t make much sense in this case in particular.
2) While the responsibility of each method is admittedly clearly separated, IMHO the class is doing too many things at the same time, which the big powers say is bad, as it infringes the Single Responsibility Principle, thus ignoring the venerable Separation of Concerns mantra. Shielding several unrelated tasks behind the same API, the class accesses the database via PDO, builds the required queries here and there, and additionally implements the URL shortening algorithm. Perhaps you might want to encapsulate the whole shortening algorithm in a separate, polymorphic class, whose instance not only could be injected in the constructor or in a setter, but would let you implement different shortening algorithms, all without having to modify your client code. More flexibility, while coding to interfaces, all in the same package :).
We all are here to learn from each other, so I don’t want to sound picky, trust me. It’s just a couple of suggestions I thought you might want to keep in mind. Keep up the good work :)


Viewing all articles
Browse latest Browse all 42

Trending Articles