design patterns for win payroll application (I always get stuck when classes communicate with each o

  • Thread starter Thread starter Angel
  • Start date Start date
A

Angel

I'm in the process of working on a Windows payroll application but I wanted
some help on what design pattern I should use. For example, if my main Form
needs all active employees in the DB, I'd call from within the form, a
method called activeEmployees from class Employees. Then I'd have another
class Connection that would do the actual connection to the DB (Oracle or
SQL Server).
I've tried this before but I get stuck when sending data from one class to
the other. For example, after activeEmployees() is called during a button
click, from where should I instantiate the Connection class and call
makeConnection(DB)? And, once Connection.makeConnection(DB) is executed and
the DB is open, how will Employees.activeEmployees() have access to that
open connection? And finally, how would I be able to send that data in
activeEmployees to the initial button click that called it?

Any help would be appreciated.
 
Hi Angel,

I will try to describe my current design cause I think that it can help you.

I have a class Employee this class has a static property named EmployeeList
that return a strong typed collection of Employee. The thing for do it
static is cause I can load it at the start and keep it in memory, therefore
any other call to EmployeeList does not have to go to the DB.

I used a class named DataProvider to implement the interaction with the DB
backend, this class has several methods: ExecuteNonQuery( IDbCommand ) ,
ExecuteScalar( IDBCommand) , etc
now each class like Employee implement a Save() operation, inside this
method it created a Command , and call to DataProvider.ExecuteScalar() ,
now as I' m using SQL2K I create a SqlCommand,

In this escenario a Employee instance knows how it have to save it self and
it's his responsability to build the IDBCommand instance to do so, then it
use the DataProvider class to send this command to the DB, in the same way
DataProvider knows how to interact with the DB and all it does is execute
the commands other classes send to it.


Hope this help,
 
Back
Top