added factory design pattern code.