Pregunta de entrevista de MathWorks

Write code for singleton pattern

Respuestas de entrevistas

Anónimo

9 sep 2020

public class Singleton{ private static Singleton uniqueInstance; private Singleton() {} //do noting in constructor public static Singleton getInstance(){ if (uniqueInstance == null ) { uniqeInstance = new Singleton(); } return uniqueInstance; } Source: Head First Design Patterns You need to class Singleton.getInstance() without explicitly creating an object. Since the constructor is private, only methods inside the class can invoke it. So the only way to create a new instance is through get the Instance() method. Once created, the if condition will not allow another new instance.

Anónimo

29 ene 2021

In these sorts of interviews you really need to drill down and understand what the interviewer is looking for. A good way to simulate a real interview experience is to do a mock with one of the MathWorks Software Engineer experts on Prepfully, rated super strongly on TrustPilot... prepfully.com/practice-interviews