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
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