4

The company I work for has been doing some arguably odd things in their source code.

One of these things I can't wrap my head around (no pun intended) is the benefit of wrapping a List<T> in a class TList.

Example

public class ThingModel
{
    //model properties
    public string Name { get; set; }
}

public class ThingModelList : List<ThingModel>
{
    //this is just an empty wrapper, no code is in here in our source
}

in the methods that use a list of ThingModel you would do ThingModelList = new ThingModelList(); rather than List<ThingModel> = new List<ThingModel>();

I don't see the benefit of doing this, and it's confused me multiple times (especially with longer names). Maybe someone could give me some insight into the benefits?

Wiktoria Prusik
  • 840
  • 4
  • 15
Pim Schwippert
  • 453
  • 7
  • 18
  • 1
    Cannot see any benefit in the case you have shown (i.e where it contains no code), but it can be useful in some scenarios. For example `SelectList` is `IEnumerable`, and it provides constructors that allow you to generate `IEnumerable` for use in dropdownlists –  Aug 07 '18 at 08:25
  • 1
    The only thing I would see could be the ability to add, expand or change the behaviour of the class afterwards, even when its been used in a lot of places. – Oliver Aug 07 '18 at 08:26
  • I see where you're coming from, but in this case they just use it as a different way to write List as FooList. So I guess it has no benifits? – Pim Schwippert Aug 07 '18 at 08:26
  • I've done it once so my collection can implement ITypedList, which was a requirement for a third party library. – MineR Aug 07 '18 at 08:48
  • A reason could be brevity. Generic class definitions can be lengthy. Recently I had to work with an array of `List>`. I inherited from `List` so that I can work with a `Bucket[]` instead: `private class Bucket : List> { }` – Theodor Zoulias Sep 16 '19 at 09:41

0 Answers0