473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Object Hierarchy: HowTo

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 !
Nov 20 '05 #1
2 1909
On 2004-04-05, tinman <dw****@yahoo.com> wrote:
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...

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
If it's worth hacking on well, it's worth hacking on for money.
Nov 20 '05 #2
On 2004-04-05, tinman <dw****@yahoo.com> wrote:
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...

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
If it's worth hacking on well, it's worth hacking on for money.
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: archway | last post by:
Hi, I would like to build a hierarchy of ProductNode objects like so ProductNode ---Product Node ---ProductNode ------ProductNode ------ProductNode ---ProductNode
6
by: NewToDotNet | last post by:
I am getting "Object reference not set to an instance of an object. " when I attempt to open a C# windows service class in design view, although I was able to initially create the service and open...
11
by: Vishal Naidu | last post by:
i m a college student in my second year..... my queston is.. is it really possible to write object oriented code in C ? and if yes how do we achieve abstration, polymorhism , hierarchy etc. in C
16
by: Elad | last post by:
Hi, I have an application that is made up of several executables. I need all these executables to use the same instance of an object. What is the best, most efficient way to approach this? ...
1
by: tinman | last post by:
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...
15
by: mr.peteryu | last post by:
Hi, Can someone explain the idea behind casting to an interface? For example: -> I have an IInterface that contains a Read() method. -> I have an object "obj" that implements IInterface. ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
5
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a...
7
by: v4vijayakumar | last post by:
Is it possible to implement member object's virtual functions, in the containing class? If not, is it possible to simulate this behavior? ex: class test { protected: virtual void fun() = 0;...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.