...

/

Reusing the Same Object Instance

Reusing the Same Object Instance

Learn which design patterns to implement when using the same instance of an object in the application.

Problem statement

Let’s imagine that we have a requirement to use exactly the same object instance throughout our entire application, regardless of whether the classes that use it can communicate directly with each other or not.

One thing we can do is instantiate it in one place and then pass the instance to every single class. This will work, but it’s less than desirable. It means that we’ll have to write a lot of extra code that’ll be hard to read and maintain.

Plus, there’s nothing that would stop passing a different ...