Object Hierarchy: HowTo

  • Thread starter Thread starter tinman
  • Start date Start date
T

tinman

Hi...

I would like to achive the following object model in VB.NET.....not too sure
how to achieve this but in VB6 I can declare the Project as
PublicNotCreatable
so as to prevent external instancing of the Project class....

Example:

Employee
|
| - - - Projects (this is a collection)
|
| - - - Project

How can I make the Projects and Project object ONLY accessible via the
Employee object ( as in this case the model implies that 1 employee can have
1 or more Projects assigned to him) ?

Appreciate any assistance on this.....

Cheers !
 
Hi...

I would like to achive the following object model in VB.NET.....not too sure
how to achieve this but in VB6 I can declare the Project as
PublicNotCreatable
so as to prevent external instancing of the Project class....

Example:

Employee
|
| - - - Projects (this is a collection)
|
| - - - Project

How can I make the Projects and Project object ONLY accessible via the
Employee object ( as in this case the model implies that 1 employee can have
1 or more Projects assigned to him) ?

Appreciate any assistance on this.....

Cheers !

You put the object model in an object library and you mark the
constructors as friend. That way, the class can't be crated by an
outside object...

Imports System
Imports System.Collections

Namespace MyObjectLibray

Public Class Employee
Private _Projects As New Projects
....

End Class

Public Class Projects
Inherits CollectionBase

Friend Sub New()
MyBase.New()
End Sub

...
End Class

Public Class Project
Friend Sub New()
MyBase.New()
End Sub

...
End Class

End Namespace


Then, you just reference the object library from your main project, and
it will not be able to directly create instances of Projects and
Project...
 
Back
Top