Singleton StockExchange, further question on implementation


While reading code on implementation part, you can find the following:

public class StockExchange {

  private static StockExchange stockExchangeInstance = null;

  // private constructor to restrict for singleton
  private StockExchange() { }

  // static method to get the singleton instance of StockExchange
  public static StockExchange getInstance()
    if(stockExchangeInstance == null) {
      stockExchangeInstance = new StockExchange();
    return stockExchangeInstance;

  public static boolean placeOrder(Order order) {
    boolean returnStatus = getInstance().submitOrder(Order);
    return returnStatus;

My question would be where to implement getInstance().submitOrder()? Is it private method of the same singleton class? If yes, then why we would have two methods with names placeOrder() and submitOrder()?


Hi @Nursultan_Jubatyrov
Yes, it is a private method, secondly, the method names are just for the implementation purpose.
Hope it will help, Thank you

1 Like