abstracting a class or property
-
I have a lot of objects to create and I am wondering if I can build them with a parameter. I set 2 examples below with my Account and a Contact object's Data property. Can I have a parameter passed in during object instantiation that is the object type use this boiler plate for all of my classes? I don't know if there is such a thing as a class Template or Class Macro or Parameritized Class animal that I can use. Thanks for taking the time to look at the code. William '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Account Get Dim obj As Account = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Account) m_olastaccessed(id) = DateTime.Now Else obj = New Account obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Contact Get Dim obj As Contact = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Contact) m_olastaccessed(id) = DateTime.Now Else obj = New Contact obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property
-
I have a lot of objects to create and I am wondering if I can build them with a parameter. I set 2 examples below with my Account and a Contact object's Data property. Can I have a parameter passed in during object instantiation that is the object type use this boiler plate for all of my classes? I don't know if there is such a thing as a class Template or Class Macro or Parameritized Class animal that I can use. Thanks for taking the time to look at the code. William '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Account Get Dim obj As Account = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Account) m_olastaccessed(id) = DateTime.Now Else obj = New Account obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Contact Get Dim obj As Contact = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Contact) m_olastaccessed(id) = DateTime.Now Else obj = New Contact obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property