Chapter 11
What technique can we use to implement the abstract factory pattern?
To implement the abstract factory pattern, we can create a hierarchy of abstract types. Then, we can implement concrete functions that take a singleton type in the argument. By way of multiple dispatches, we should be able to call the right function for the right platform or environment.
How do we avoid a singleton from being initialized multiple times in a multithreaded application?
To avoid multiple initializations of a singleton, we can use a reentrant lock to synchronize the threads. The first thread would be able to obtain the lock and initialize the singleton, while the other threads should wait until the initialization is finished. The lock must be released ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access