My program receives information from an external source (maybe a file, a database, or something else that I can solve in the future).
I want to define an interface with all my data needs and classes that implement it (for example, a class for receiving data from a file, another for the database, etc.).
I want the rest of my project not to care about where the data comes from, nor do I need to create any object to receive the data, for example, to call "DataSource.getSomething ();"
To do this, I need a DataSource to contain an interface type variable and initialize it using one of the concrete implementations and expose all its methods (which come from the interface) as static methods.
So, let's say the name of the interface is K, and specific implementations are A, B, C.
How I do it today:
public class DataSource { private static K myVar = new B();
This is very bad, since I need to copy all the interface methods and make them static so that I can delegate it to myVar and many other obvious reasons.
What is the right way to do this? (maybe there is a design template for it?)
** Note. Since this will be the basis of many other projects, and I will use these calls from thousands (if not tens of thousands) of lines of code, I insist that it be as simple as "DataSource.getSomething ();", I do not want anything like this "DataSource.getInstance (). GetSomething ();" **
Edit: I was asked to use a DI infrastructure such as Guice, does this mean that I will need to add DI code to each entry point (that is, the "main" method) in all my projects, or is there a way to do this once for all of projects