Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

I think we shall use Chain of responsibilities pattern..
There can be different objects which are in chain, and one among them would serve the request..
For example, There is already an object which serves to write log to file and
add new object which serves writing log to Database..

- amidala.shiva November 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Logger {
   private:
      bool db_flag;
      string log_name;
      static Logger *m_pInstance; 
      Logger (){};
     Logger(const Logger &);
     Logger &( operator =(const Logger &) {};
     
     
   public:
      static Logger * Instance() {};
     bool openlogfile(bool flag,string logname);
     void writetoLog();      
     bool closeLog();
      
}

Logger * Logger::m_pInstance = NULL;
Logger * Logger :: Instance(bool flag,string logname) {
    if (!m_pInstance) 
        m_pInstance = new Logger(flag,logname);
          
   return m_pInstance;
}

bool Logger::openlogfile(bool flag,string logname) {
    db_flag = flag;
    log_name = logname;
    if (db_flag){
      //connect to DB
    } else
      open (logname);
}

Call in main :

Logger ::Instance()->openlogfile(bool true,"myDB");
Logger::Instance()->writetofile("message 1..");

- iwanna June 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I feel the interviewer has asked for the AbstractFactory Implementation of the Logger class which should be singleton.

- Nirbhay Singh July 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Exactly. We need to write a Abstract Storage Class from which DBStorage and FileStorage are inherited, Then by using Factory class on top of it to determine which function to invoke during run time from Singleton Logger class.

- deepak_gta July 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Designing a Configurable Logging framework using Observer Design Pattern

[http]://thispointer.com/designing-a-configurable-logging-framework-using-observer-design-pattern/

- Varun August 18, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More