Object Visibility, whats the best way?

Discussion in 'Microsoft Dot NET' started by dgleeson3@eircom.net, Aug 15, 2007.

  1. Guest

    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
     
    , Aug 15, 2007
    #1
    1. Advertisements

  2. On Aug 15, 12:40 pm, wrote:
    > 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
     
    rowe_newsgroups, Aug 15, 2007
    #2
    1. Advertisements

  3. Jack Jackson Guest

    On Wed, 15 Aug 2007 09:40:28 -0700, wrote:

    >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.
     
    Jack Jackson, Aug 15, 2007
    #3
  4. Guest

    Hi Guys

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

    Thanks

    Denis

    On Aug 15, 6:36 pm, Jack Jackson <> wrote:
    > On Wed, 15 Aug 2007 09:40:28 -0700, wrote:
    > >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.- Hide quoted text -
    >
    > - Show quoted text -
     
    , Aug 16, 2007
    #4
  5. On Aug 16, 7:28 am, wrote:
    > Hi Guys
    >
    > Thanks for the suggestions.
    > I think your second suggestion is the most appropriate Jack.
    >
    > Thanks
    >
    > Denis
    >
    > On Aug 15, 6:36 pm, Jack Jackson <> wrote:
    >
    > > On Wed, 15 Aug 2007 09:40:28 -0700, wrote:
    > > >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.- Hide quoted text -

    >
    > > - Show quoted text -


    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
     
    rowe_newsgroups, Aug 16, 2007
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eva

    Whats the best control to use?

    Eva, Oct 27, 2003, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    143
    Robert Morris
    Oct 28, 2003
  2. moondaddy

    Whats the best group for .net 3.0 and xaml questions

    moondaddy, Dec 18, 2006, in forum: Microsoft Dot NET
    Replies:
    10
    Views:
    258
    Steven Cheng[MSFT]
    Dec 21, 2006
  3. moondaddy

    Whats the best way to kill an object?

    moondaddy, Feb 28, 2007, in forum: Microsoft Dot NET
    Replies:
    2
    Views:
    203
    moondaddy
    Feb 28, 2007
  4. moondaddy
    Replies:
    2
    Views:
    179
    moondaddy
    Mar 2, 2007
  5. moondaddy

    Best way to clear contents of a stringbuilder object

    moondaddy, Feb 7, 2008, in forum: Microsoft Dot NET
    Replies:
    7
    Views:
    909
    moondaddy
    Feb 8, 2008
Loading...

Share This Page