Wednesday, November 3, 2010

C++ Series - Interview questions

How to prevent a class from inheritance ?

) Private Constructor(s)
class CBase 
public
static CBase* CreateInstance()  
{  
  CBase* b1 = new CBase(); 
  return b1; 
 } 
private
 CBase() { } 
 CBase(CBase3) { } 
 CBase& operator=(CBase&) { } 
}; 
2) Using CSealed base class, private ctor & virtual inheritance
class CSealed 
private
 CSealed() { 
 } 
 friend class CBase
}; 
class CBase : virtual CSealed 
 public
 CBase() { 
 } 
 }; 
3) Using a CSealed base class, protected ctor & virtual inheritance
class CSealed 
 protected
 CSealed() { 
 } 
}; 
 class CBase : virtual CSealed 
public
CBase() { } 
}; 

C++ Series - Interview questions

What are the various reasons to use virtual destructor in base class?

1. Without a virtual destructor the proper destructor may not be
called:

struct B {~B();};
struct D : B {~D();};
B* b new D;
delete b; // <--------- Will not call D::~D() !!!!!

2. Without a virtual destructor operator delete(void* size_t) may
not be called with the correct size.

struct B {~B(); operator delete(void* size_t);};
struct D : B {~D();};
B* b new D;
delete b; // <--------- Will call operator delete(void* size_t) with
// the size of B not the size of D!!!

3. Without a virtual destructor and when MI is used operator
delete(void*) or operator delete (void* size_t) may be called with
the wrong address.

struct B {~B();};
struct A {};
struct D : A B {~D();};
B* b new D;
delete b; // <--------- May not pass to operator delete the address
// that was returned by operator new!!!

C++ Series - design patterns - 1

Singleton design pattern - Most commonly used pattern and most powerful pattern if used properly.

To say about this design pattern in a single sentence ...
This patterns help to create and use a single object instance through your entire program no matter how many time your initiate your class object.

As simple implementation of this is as below:


class DBconnector{

public:
   static DBconnector* Instance();   -- This function is used to create the object and return the pointer of the object to be used. If the object already exists it just returns the pointer.
   bool openDBconnection(std::string logFile);
   bool inserttoDB();
   bool extractfromDB();

private:

   DBconnector(){};  // The default ctor is made private so that an object cannot be created by just instantiating the class.
   DBconnector(DBconnector const&){};             // copy constructor is made private so that  fails in creating an intermediate object while copying and help to prevent only single instance is prevailing at all moment of time.
   DBconnector& operator=(DBconnector const&){};  // assignment operator so it fails while assigning any other object to this instance.
   static DBconnector* m_pInstance; // Pointer to the actual object , which is single through the program.

};

Multi threading issues with the above program:

Coming soon .. Keep watching.

Tuesday, November 2, 2010

Article Series - Does cloud computing change IT architecture in Banking

Over the past one year , i have been hearing about the word "Cloud Computing" from many technology companies. There was attending seminars over a couple on months on cloud computing in Singapore and i find two of them very interesting.

First one was from MAS (Monetary Authority of Singapore) at SMU and second was from Amazon web services the largest provider of cloud computing services. Each of them have totally opposite opinion on cloud computing.

To tell you some thing about cloud computing  in one sentence , it a computing service exposed to public over internet. That means , you have to pay for the usage of service and only pay as much as you use the service. Just like your utility bill. As in the case of utilities like water and electricity , the user are unaware of how the drinking water , from where did the drinking water come from , similar is the case with Cloud Computing , the user will be unaware of how is the underlying IT infrastructure scaled , or where is the IT infrastructure available , they just use the service and pay for it.

The MAS speaker was concerned about the banks to expose their data on a public cloud. Banks can save a lot of money , if they are able to minimize the cost of their operations. When they start to use the cloud , they can pay as less as 5 USD per hour of the server computing services , but the concern from MAS was that , is that computing service secure enough to protect the depositors information.

The Amazon speaker has given the big picture on how many firms are converting from traditional IT infrastructure set up to cloud computing services and more interesting was there were some of US government agencies started using cloud computing as their primary computing source of IT infrastructure. This clearly shows that cloud computing service has the required security controls in place.

I think the real big gap between the above two groups is the way they look at the security concerns prevailing over cloud computing. Once , this gap is clearly understood and perceived by both the groups , then only can the real era of cloud computing will start in the world of banking.