Skip to main content

Posts

Showing posts from April, 2013

Interview question - Database schema design

This is a database schema design interview question I have attended recently. The interviewer asked me to design DB schema for the below data in an efficient and normalized way and write a query to retrieve " first name, last name, department and work phone numbers of  all employees who are managed by Frank Callea". The data is given below in the diagram. The schema that I have designed is given below. I have created 3 tables as below. Employee Table      EMPID FIRSTNAME                        LASTNAME                             DEPTID      MGRID ---------- -------------------------------- -------------------------------- ---------- ----------          1 Trad                             Lin                                       1          2          2 Frank                            Callea                                    2          0          3 Fred                             Snyder                                

Factory Design Pattern using Reflection

Here I have given an implementation of Factory design pattern in Java using reflection.Please refer to the below link for a quick presentation about Java Refection APIs. www.cs.washington.edu/education/courses/.../reflection.ppt I am creating a DB factory which will create an instance of Database manager objects depends on the argument which is passed. Assume that we have an application running in 2 different environment where one environment uses Oracle as a database and another uses Solaris as a database.Upon initialization of the program we have to create a DB manager instance which should return Oracle or Solaris DB manager for the program. Here I have used reflection to avoid modification to the Factory class if we need to support a new data base tomorrow. I have factory class as below, DBFactory.java import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; public class DBFactory { private static HashMap m_Regi