martedì 21 gennaio 2014

Some questions that some pm was asked me in some job interviews

Private versus Protected

Private keyword is used to limit a property or a method visibility only at owner class.
Protected keyword insteed is used to limit a property or a method visibility at owner and its child classes.

How implement singleton pattern?

Singleton pattern is used to garantee only one instance of an object. This pattern is often used on a database connection to have only one instance of it.
To implement a singleton pattern, it needs to have a private static property to store instance object.
Also it needs a public static method, named often getInstace(); so if an object want to instance the object that implements singleton pattern, it can call statically getInstance() method.
This method simply returns a new instance of the object if it haven't already been one or return the same instance if it is already present.

What is the difference between abstract class and interface? 

It's better use an interface when you want to force a developer that would like to communicate with your software, to implement a set number of method in own class.
It's better use an abstract class, when it want to provide some base methods that will help about development of a child class.

What is the difference between require and include?

Require and include are used to insert the content of a php file into another php file. There is a difference between their.
Require will produce a fatal error and stop the script if it fails while include will produce only a warning message and the script continue.

How is a session? Could you explain it please?

A PHP Session variable is used to store information about an user session or to mantain web application state. Session is necessary because http protocol is stateless so dosn't maintain the state