I've just started studying design patterns. While I was studying " Decorator Pattern " I noticed that we use Interface in order to instantiate an object.
I will demonstrate my example by using the decorator pattern.
public interface GuitarMets {
public String getDesc();
public double getCost();
}
This is my interface and this interface is implemented by another class that will be used for the creation.
And in my main class I have lines like this.
public class MainClass {
public static void main(String[] args){
GuitarMets guitar = new Sound(new Guitar());
System.out.println(guitar.getDesc());
System.out.println(guitar.getCost());
}
}
So what I could not figure out is that, since we cannot create an object from Interfaces, how we are able to use it in order to instantiate objects from the interface?
I hope my question is not weird and finds you well.