Results 1 to 2 of 2

Thread: Classes in VB.NET OOP

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    5

    Classes in VB.NET OOP

    Hi!
    I need some help with how to organize classes in VB.NET. I have a class called parent with methods for adding, deleting etc. But I also need a method that returns a list of all the parents, a list with parent objects. Where do I put this method? Do I put it in the parent class or do I need to make another class called parents? Or is there a better way to solve this question?

    Thanks!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Classes in VB.NET OOP

    If you need a collection of Parent objects then you can simply use the generic List(Of T) class or, more specifically in your case, the List(Of Parent) class. If you need custom functionality then you could declare a ParentCollection class that inherits Collection(Of T). The base class provides all the standard collection functionality and then you can add your own custom stuff, e.g. validation on addition.

    As for a method that returns a collection of Parent objects, the right place to declare that depends on the circumstances. You definitely wouldn't put it in the Parent class itself. You might have a repository class or engine class or service class that's responsible for shuffling data between the application and a data source. It really depends on exactly what you're trying to achieve and the architecture you're using.

    At my office, we used to use the ECC pattern, where we would define an item class for each type of database record, a corresponding collection class that would store multiple items of that type and an engine class that could get items and collections of that type from the database and save items and collections to the database. Now that we mostly use the Entity Framework, we create a repository class that wraps the EF data model and then have a service layer between that and the app.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width