Is global constants an anti-pattern?
Global constants are fine. Global (non-constant) variables are the work of the devil.
Global constants are fine. Global (non-constant) variables are the work of the devil.
Did I “get” it? Sorry to say, not quite. The goal of Context Object is not to pass lots of parameters to methods implicitly, as a means of by-passing strong typing and encapsulation. The goal is to store scoped data in a general, but managed way, independent of protocols and presentation technology. Data stored within … Read more
Singletons can implement interfaces and inherit from other classes. Singletons can be lazy loaded. Only when it is actually needed. That’s very handy if the initialisation includes expensive resource loading or database connections. Singletons offer an actual object. Singletons can be extended into a factory. The object management behind the scenes is abstract so it’s … Read more
In an optimistic update the UI behaves as though a change was successfully completed before receiving confirmation from the server that it actually was – it is being optimistic that it will eventually get the confirmation rather than an error. This allows for a more responsive user experience.
The visitor pattern’s visit/accept constructs are a necessary evil due to C-like languages’ (C#, Java, etc.) semantics. The goal of the visitor pattern is to use double-dispatch to route your call as you’d expect from reading the code. Normally when the visitor pattern is used, an object hierarchy is involved where all the nodes are … Read more
Honestly, the two patterns are pretty similar in practice, and the defining difference between them tends to vary depending on who you ask. Some popular choices are: States store a reference to the context object that contains them. Strategies do not. States are allowed to replace themselves (IE: to change the state of the context … Read more
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
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
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
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