New answers tagged

0

I think the question is a symptom, not a solution. I recently read a lot about Singletons being bad and how dependency injection (which I understand as "using interfaces") is better. When I implemented part of this with callbacks/interfaces/DI and adhering to the interface segregation principle, I ended up with quite a mess. A solution looking for a ...


0

Your question is draws on a large article. But I’ll be shorter. Now I’am just learning Scala and also have similar question as your and I think answer on it will came on time to you while your experience in Scala will growing. You can pick up some well known projects and learning through reviewing code. Good way is to start to contribute project that you ...


1

"Class heirarchy" is a bit of a red flag. Hypothetical: a web page with 5 widgets. The page is not an ancestor of any of the widgets. It may hold a reference to those widgets. But it is not an ancestor. Instead of class heirarchy, consider using composition. Each of the 5 widgets can be constructed on its own, without reference to the other widgets or ...


0

One of the things that's bothered me for a long time about the debate around the Singleton pattern is that almost no one looks at the original design pattern from GoF. They are talking about a shallow simplification of the pattern. I think this is pretty disrespectful to the authors of a book that's probably one of the most influential texts in software ...


2

A good alternative to singletons is using Dependency Injection as described in Paul K's answer here. Create and initialise a class at the highest necessary scope, then pass it down by reference. When dealing with existing globally accessible state/resources, my solution would be to: 1) Determine what parts of the global state are needed. 2) Encapsulate ...



Top 50 recent answers are included