473,756 Members | 3,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
PublicNotCreata ble
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 1939
On 2004-04-05, tinman <dw****@yahoo.c om> 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
PublicNotCreata ble
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.Collecti ons

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.c om> 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
PublicNotCreata ble
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.Collecti ons

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
1409
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
7145
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 in design view. This happens once I restarted Visual Studio adn opened teh solution Any ideas on how to fix this would be appreciated.. BR ::Ben
11
2298
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
10135
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? Thanks a lot!
1
361
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 instancing of the Project class.... Example: Employee
15
26299
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. Why would someone do the following and what does it mean?
16
2898
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 will stay alive. Is this correct? If this is correct, I've got a problem. Let's say I've got an object Customer that has an PurchaseList (Collection) of Purchase objects. Now, these Purchase objects were pulled from a datasource Datasource. The...
5
3173
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 instance is created by "calling" a class object.
7
1786
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
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9273
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9711
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8712
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5141
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.