Architecti–din nou

Am citit de multe ori Joel Spolsky, http://www.joelonsoftware.com/items/2008/05/01.html si http://www.joelonsoftware.com/articles/fog0000000018.html .

Problema este ca ei nu isi dau seama.

De ce scriu asta? Pentru ca am citit un blogpost nou , http://mkartak.blogspot.ro/2016/07/unknown-disposables-disposing-of-non.html .

Treaba ar fi rezolvata mai simplu daca IContract ar fi

IContract: IDisposable

si ar fi utilizat un simplu using.


using (IContract contract = new ContractFactory().Create()){



}

Pentru ca nu se vrea , probabil din considerente arhitecturale , considera ca e mai simplu acest cod:

using (DisposableInterface<IContract> contract = new DisposableInterface<IContract>(new ContractFactory().Create()))

{

IContract instance = contract.Instance;

// all the interaction now happens with the "instance" reference

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *