samedi 18 juillet 2015

elegant way for an object composed of other objects to fail in c#

if you have an object that is composed of a bunch of other objects ie:

class A{
  B b {get;}
  C c {get;}
  private A(){
    b = B.Make();
    c = C.Make();
  }
}

And classes B and C are set up to return null when an exception is thrown, is there a better way than mass-checking for null in As members for null to have it fail as well?

Admittedly my understanding of exception management is poor, but it would make sense for B and C to not handle their own exceptions and instead let them bubble up to A, thereby circumventing the entire null fiasco. But what if they're classes with uses independent of A?

Aucun commentaire:

Enregistrer un commentaire