Let's consider an online shopping website. If you are willing to buy an electrical gadget which is in huge demand, you have to wait till the product is available. Since you are very eager to buy this product so you will register it on that site. If that product is available, the site will notify you either by mail or message. Here, you are the observer. Similarly, many observers are eager to buy that product. Here, observers won't have information of other observers, but the online shopping site (Subject) knows information about all the observers.
The subject has information like Phone number, email id of all the observers.
Whenever the product is available, the subject sends the notification to all the observers.
public class Socket
{
public Voltage getVoltage()
{
return new Voltage(240); //In India 240 is the default voltage
}
}
For tutorial videos, please check out the premium Software Design Pattern course on Udemy.