What is a wrapper class?

In general, a wrapper class is any class which “wraps” or “encapsulates” the functionality of another class or component. These are useful by providing a level of abstraction from the implementation of the underlying class or component; for example, wrapper classes that wrap COM components can manage the process of invoking the COM component without … Read more

How do the Proxy, Decorator, Adapter, and Bridge Patterns differ?

Proxy, Decorator, Adapter, and Bridge are all variations on “wrapping” a class. But their uses are different. Proxy could be used when you want to lazy-instantiate an object, or hide the fact that you’re calling a remote service, or control access to the object. Decorator is also called “Smart Proxy.” This is used when you … Read more

In a PHP project, what patterns exist to store, access and organize helper objects? [closed]

I would avoid the Singleton approach suggested by Flavius. There are numerous reasons to avoid this approach. It violates good OOP principles. The google testing blog has some good articles on the Singleton and how to avoid it: http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-join-new-project.html http://googletesting.blogspot.com/2008/05/tott-using-dependancy-injection-to.html http://googletesting.blogspot.com/2008/08/where-have-all-singletons-gone.html Alternatives a service provider http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html dependency injection http://en.wikipedia.org/wiki/Dependency_injection and a php explanation: http://components.symfony-project.org/dependency-injection/trunk/book/01-Dependency-Injection This … Read more

Ways to eliminate switch in code [closed]

Switch-statements are not an antipattern per se, but if you’re coding object oriented you should consider if the use of a switch is better solved with polymorphism instead of using a switch statement. With polymorphism, this: foreach (var animal in zoo) { switch (typeof(animal)) { case “dog”: echo animal.bark(); break; case “cat”: echo animal.meow(); break; … Read more

Why is Singleton considered an anti-pattern? [duplicate]

To help with answering, here is more about the anti-pattern comment: it is overused, introduces unnecessary restrictions in situations where a sole instance of a class is not actually required, and introduces global state into an application From: http://en.wikipedia.org/wiki/Singleton_pattern For more on this you can look at: https://www.michaelsafyan.com/tech/design/patterns/singleton Here is a great ending to the … Read more