Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class Multiplicity Design Patterns...need ideas

Status
Not open for further replies.

robdog09

IS-IT--Management
Aug 23, 2005
19
US
Most developers that have to start a new app, look at their database, and try to derive some sort of UML design from the ERD, which is great. I am one of those, which has a dozen or so classes for an app all encapsulating logic and information related to that class.

A problem i run into from time to time is how to represent multiplicites in VB. For example, a "manager" has multiple "employees" working for him/her. With managers and employee being the classes, a manager class should have reference to a set of instances of the employee class. How i do this now is using .NET 2.0 Generics. I maintain a list of my employees (List(of Employee)). I place logic into the manager class to maintain and search that list.

Where my design gets hacky is how i construct the classes. In the constructor of manager, i retrieve a datareader of all the employees assigned to that manager, then do this

-----------------------
while dr.read
dim obj as new Employee(dr)
if obj.IsValid() then lstEmps.add(obj)
end while
-----------------------

my employee constructor looks like...

-----------------------
Sub New(dr as sqldatareader)
try
_empid = dr("empid")
_empname = dr("name")
......
IsValid=true
catch ex as exception
IsValid=false 'maybe throw new exception("BAD")
end try
end sub
-----------------------


Is this good, bad? thoughts???? Need some ideas
 
that design looks ok to me, but rather than declaring an employee object each time u could just have an .Add method to the employee object. here the employee object is initialised only once.


but again thats just a view point...

Known is handfull, Unknown is worldfull
 
Yea i was thinking that but i dont want to call that query EACH time. Want to run it once and get it in memory then pass it around
 
>>Yea i was thinking that but i dont want to call that query EACH time. Want to run it once and get it in memory then pass it around

how can u do that? wont the query change for each emp?

Known is handfull, Unknown is worldfull
 
The data will change but not the query. Either im doing

spGetEmployeeInfoByEmpId 123
or
spGetEmployeeInfoAll

In this example, both will give me the same fields but one will return one record and the other ALL my employees. So, each time dr.read passes, it will advance to a new employee passing the constructor a new record of data

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top