|
-
Jun 28th, 2011, 04:01 AM
#1
Thread Starter
New Member
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!
-
Jun 28th, 2011, 04:24 AM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|