Object Visibility, whats the best way?

D

dgleeson3

Hello All

I have three classes Form1, DataBase_Manager and Users.
Form 1 creates two object of type DataBase_Manager and Users as below.

Public Class Form1
Inherits Form

Public DataBase_Manager1 As New DataBase_Manager
Public User1 As New Users


My idea is that the DataBase_Manager1 object handles all database
interactions. The User1 object needs data from the database and must
ask the DataBase_Manager1 for the data.

So the user class has a function which needs to call a function in the
DataBase_Manager1 to have it retrieve the required data. How do I make
the functions in DataBase_Manager1 visible to the object User1. And
what is the best OO way of doing this in VB.NET

Many thanks for all replies.

Denis
 
R

rowe_newsgroups

Hello All

I have three classes Form1, DataBase_Manager and Users.
Form 1 creates two object of type DataBase_Manager and Users as below.

Public Class Form1
Inherits Form

Public DataBase_Manager1 As New DataBase_Manager
Public User1 As New Users

My idea is that the DataBase_Manager1 object handles all database
interactions. The User1 object needs data from the database and must
ask the DataBase_Manager1 for the data.

So the user class has a function which needs to call a function in the
DataBase_Manager1 to have it retrieve the required data. How do I make
the functions in DataBase_Manager1 visible to the object User1. And
what is the best OO way of doing this in VB.NET

Many thanks for all replies.

Denis

If the Users class is going to consume the DataBase_Manager class, it
should have it's own instance of the class. Why not just add a
DataBase_Manager to the Users class?

Also, assuming it won't break any inheritance chains you could just
have Users inherit from DataBase_Manager giving it a copy of all it's
methods/properties.

Another option would be to make the methods in DataBase_Manager shared
(static in C#) so any class can call the methods without needing to
instantiate the class first.


Thanks,

Seth Rowe
 
J

Jack Jackson

Hello All

I have three classes Form1, DataBase_Manager and Users.
Form 1 creates two object of type DataBase_Manager and Users as below.

Public Class Form1
Inherits Form

Public DataBase_Manager1 As New DataBase_Manager
Public User1 As New Users


My idea is that the DataBase_Manager1 object handles all database
interactions. The User1 object needs data from the database and must
ask the DataBase_Manager1 for the data.

So the user class has a function which needs to call a function in the
DataBase_Manager1 to have it retrieve the required data. How do I make
the functions in DataBase_Manager1 visible to the object User1. And
what is the best OO way of doing this in VB.NET

Many thanks for all replies.

Denis

If Database_Manager is not needed in the form except for use by Users,
put it in Users. You can do that anyway if it would work to have two
copies of Database_Manager.

If you want only one copy in the form, then you need to pass the
reference to Database_Manager to Users. You can do that with a
parameter on the Users constructor (New()) or by calling a method in
Users from the Form code after both are instantiated.
 
D

dgleeson3

Hi Guys

Thanks for the suggestions.
I think your second suggestion is the most appropriate Jack.

Thanks

Denis
 
R

rowe_newsgroups

Hi Guys

Thanks for the suggestions.
I think your second suggestion is the most appropriate Jack.

Thanks

Denis

One other option is to make the Database_Manager implement the
Singleton pattern. That way all consumers of the class will be using
the same instance of the Database_Manager.

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top