Quantcast
Channel: Alternatives to the singleton pattern - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 11

Answer by Winston Ewert for Alternatives to the singleton pattern

$
0
0

There are a few alternatives:

Dependency Injection

Every object has its dependencies passed to it when it was created. Typically either a framework or a small number of factory classes are responsible for creating and wiring the objects

Service Registry

Every object is passed a service registry object. It provides methods to request various different objects which provide different services. The Android framework uses this pattern

Root Manager

There is a single object which is the root of the object graph. By following the links from this object any other object can be eventually found. Code tends to look like:

GetSomeManager()->GetRootManager()->GetAnotherManager()->DoActualThingICareAbout()

Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>