class - C# Collection classes - yes or no -


i'm relative newbie c#, although competent programmer, , confess totally confused whether or not idea write custom collection classes. many people seem "don't", yet there whole set of base classes in c#.

here specific case. have timetable application. part of that, have service class, , service class contains collections of things service-y, such route links. route link custom class:

public class service {   public routelinks rl;    // collection of routelink types   ... }  public class routelink {     public string firststopref;     public string laststopref;     public tracks routetrack;    // collection, time of track types } 

so far have looked @ using dictionary type routelinks, because need able reference them. fine in principle. however, process of adding routelink routelinks collection involves checking see whether there, or whether extends , existing route link, or... , that, need custom add function.

so why is such bad practice create custom collection classes? why shouldn't inherit collectionbase or dictionarybase?

i should perhaps add transferring code vba [please don't shoot me :)] , there had implement custom collections.

instead of having routelinks collection type, easy solution define class, let's routelinksrepository. class contain list<routelink> , addroute(routelink) functionality other custom logic interacting collection of routelink objects. service class contain instance of repository class.

public class service {   public routelinksrepository rl;    // collection of routelink types   // ... }  public class routelinksrepository {     public list<routelink> routelinks;     public bool addroute(routelink linktoadd)     {         //custom logic on whether or not add link     }     //your other logic class  }  public class routelink {     public string firststopref;     public string laststopref;     public tracks routetrack;    // collection, time of track types } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -