Are there any viable alternatives to the GOF Singleton Pattern?

To understand the proper way to workaround Singletons, you need to understand what is wrong with Singletons (and global state in general): Singletons hide dependencies. Why is that important? Because If you hide the dependencies you tend to lose track of the amount of coupling. You might argue that void purchaseLaptop(String creditCardNumber, int price){ CreditCardProcessor.getInstance().debit(creditCardNumber, … Read more

What’s the difference between design patterns and architectural patterns? [closed]

It requires a detailed explanation but I will try to sketch the differences to best of my knowledge. Patterns are distilled commonality that you find in programs. It allows us to deconstruct a large complex structure and build using simple parts. It provides a general solution for a class of problems. A large complex software … Read more

What is an anti-pattern?

Anti-patterns are certain patterns in software development that are considered bad programming practices. As opposed to design patterns which are common approaches to common problems which have been formalized and are generally considered a good development practice, anti-patterns are the opposite and are undesirable. For example, in object-oriented programming, the idea is to separate the … Read more

Eliminating `switch` statements [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

What is the difference between Builder Design pattern and Factory Design pattern? [closed]

With design patterns, there usually is no “more advantageous” solution that works for all cases. It depends on what you need to implement. From Wikipedia: Builder focuses on constructing a complex object step by step. Abstract Factory emphasizes a family of product objects (either simple or complex). Builder returns the product as a final step, … Read more

What is the Page Object Pattern in Selenium WebDriver? [closed]

The documentation has already covered this. If you have any specific questions, feel free to edit your main post. Official: Page Objects and PageFactory on Selenuim Wiki. Page Object Design Pattern on Selenium official site. Unofficial: Do a Google search, you will get a lot info on this. Page Object Pattern Page Objects in Selenium … Read more

Which design patterns can be applied to the configuration settings problem?

I prefer to create an interface for setting query, loading, and saving. By using dependency injection, I can inject this into each component that requires it. This allows flexibility in terms of replacing the configuration strategy, and gives a common base for everything to work from. I prefer this to a single, global “settings loader” … Read more