Don't be STUPID: GRASP SOLID! Ever heard of SOLID code? Probably: It is a term describing a collection of design principles for “good code” that was coined by Robert C. Martin (aka “uncle bob”), our beloved evangelist of clean code. Programming is full of acronyms like this. Other examples are DRY (Don’t Repeat Yourself!) So, why not approach the problem from the other side for once?
Sorry, but your code is STUPID! Nobody likes to hear that their code is stupid. What characterizes such code? Singleton Tight coupling Untestability Premature Optimization Indescriptive Naming Duplication Do you agree with this list? Singleton The above is the typical database access implementation you will find in pretty much any PHP tutorial.
Now you wonder: What’s wrong with that? Well, yeah, I thought that too ^^ “I only need one connection.” And that was only one issue. // original DB classclass _DB { /* ... */ } // extending classclass DB extends _DB { /* ... */ } One word: Ugly. Tight coupling Untestability Unit testing is important. www.objectmentor.com/resources/articles/ocp.pdf. www.objectmentor.com/resources/articles/isp.pdf. www.objectmentor.com/resources/articles/lsp.pdf.