Skip to main content
Filter by
Sorted by
Tagged with
2188 votes
36 answers
674k views

The singleton pattern is a fully paid up member of the GoF's patterns book, but it lately seems rather orphaned by the developer world. I still use quite a lot of singletons, especially for factory ...
3687 votes
40 answers
1.3m views

There have been several questions already posted with specific questions about dependency injection, such as when to use it and what frameworks are there for it. However, What is dependency injection ...
AR.'s user avatar
  • 40.4k
332 votes
26 answers
185k views

My singleton accessor method is usually some variant of: static MyClass *gInstance = NULL; + (MyClass *)instance { @synchronized(self) { if (gInstance == NULL) gInstance =...
schwa's user avatar
  • 11.9k
672 votes
7 answers
570k views

I am learning GoF Java Design Patterns and I want to see some real life examples of them. What are some good examples of these Design Patterns in Java's core libraries?
143 votes
11 answers
44k views

I access my MySQL database via PDO. I'm setting up access to the database, and my first attempt was to use the following: The first thing I thought of is global: $db = new PDO('mysql:host=127.0.0.1;...
seriousdev's user avatar
  • 7,676
618 votes
13 answers
308k views

What are some common, real world examples of using the Builder Pattern? What does it buy you? Why not just use a Factory Pattern?
Charles Graham's user avatar
645 votes
22 answers
349k views

I know there are many posts out there about the differences between these two patterns, but there are a few things that I cannot find. From what I have been reading, I see that the factory method ...
Silverbolt's user avatar
  • 7,513
199 votes
6 answers
77k views

Is the following implementation, using lazy initialization, of Singleton (Meyers' Singleton) thread safe? static Singleton& instance() { static Singleton s; return s; } If not, why and ...
Ankur's user avatar
  • 11.8k
511 votes
11 answers
237k views

Fragments seem to be very nice for separation of UI logic into some modules. But along with ViewPager its lifecycle is still misty to me. So Guru thoughts are badly needed! Edit See dumb solution ...
Oleksii Malovanyi's user avatar
379 votes
10 answers
144k views

Recalling this post enumerating several problems of using singletons and having seen several examples of Android applications using singleton pattern, I wonder if it's a good idea to use Singletons ...
Martín Schonaker's user avatar
119 votes
4 answers
132k views

I've heard recently that Singleton is an anti-pattern. I know it has to do with the fact making a class singleton is like making that unique instance a global variable, but it's also doing a lot more ...
user1710031's user avatar
  • 1,279
103 votes
8 answers
35k views

From Head First design patterns book, the singleton pattern with double checked locking has been implemented as below: public class Singleton { private volatile static Singleton instance; ...
toc777's user avatar
  • 2,705
199 votes
8 answers
96k views

One stumbles upon this phrase when reading about design patterns. But I don't understand it, could someone explain this for me?
never_had_a_name's user avatar
215 votes
22 answers
204k views

How would one create a Singleton class using PHP5 classes?
Andrew Moore's user avatar
  • 95.8k
102 votes
4 answers
44k views

In JSF MVC framework who is Model, View, and Controller?
yegor256's user avatar
  • 106k
517 votes
10 answers
68k views

Why would you create a "Implicitly Unwrapped Optional" vs creating just a regular variable or constant? If you know that it can be successfully unwrapped then why create an optional in the first place?...
Johnston's user avatar
  • 21.1k
234 votes
6 answers
165k views

I have read that it is possible to implement Singleton in Java using an Enum such as: public enum MySingleton { INSTANCE; } But, how does the above work? Specifically, an Object has to be ...
Anand's user avatar
  • 21.5k
179 votes
10 answers
58k views

Recently I've read Mark Seemann's article about Service Locator anti-pattern. Author points out two main reasons why ServiceLocator is an anti-pattern: API usage issue (which I'm perfectly fine with) ...
davidoff's user avatar
  • 2,355
403 votes
11 answers
250k views

There's this one thing in C++ which has been making me feel uncomfortable for quite a long time, because I honestly don't know how to do it, even though it sounds simple: How do I implement Factory ...
Kos's user avatar
  • 72.7k
112 votes
19 answers
111k views

I've been reading about the OCP principle and how to use the strategy pattern to accomplish this. I was going to try and explain this to a couple of people, but the only example I can think of is ...
user avatar
113 votes
15 answers
118k views

I was asked a question, I wanted to get my answer reviewed here. Q: In which scenario it is more appropriate to extend an abstract class rather than implementing the interface(s)? A: If we are using ...
lowLatency's user avatar
  • 5,734
253 votes
25 answers
134k views

In the MVVM pattern for WPF, handling dialogs is one of the more complex operations. As your view model does not know anything about the view, dialog communication can be interesting. I can expose ...
Ray Booysen's user avatar
  • 30.2k
90 votes
8 answers
115k views

I understand that the N+1 problem is where one query is executed to fetch N records and N queries to fetch some relational records. But how can it be avoided in Hibernate?
Vipul Agarwal's user avatar
517 votes
21 answers
258k views

Is it possible to implement the model–view–controller pattern in Java for Android? Or is it already implemented through Activities? Or is there a better way to implement the MVC pattern for Android?
Mohit Deshpande's user avatar
575 votes
31 answers
234k views

Most of the examples quoted for usage of Dependency Injection, we can solve using the factory pattern as well. Looks like when it comes to usage/design the difference between dependency injection and ...

1
2 3 4 5
65