Avoid Exposing Collections Directly as Properties
page 4 of 6
by Steven Smith
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28584/ 54

Overriding Intended Behavior

Even if you only expose your type as an IEnumberable, sneaky clients of your class can still get to its underlying methods if they guess correctly.  As the next test shows, if a consumer of your class is able to guess (or determine through reflection or a decompiler) the actual underlying type of your interface, then all bets are off and they can destroy your data at will:

We can probably safely say that any developer who so blatantly overcomes your attempts at encapsulating data deserves the bugs they create by doing so.  However, there is one more alternative approach


View Entire Article

User Comments

Title: Picture links all broken (404)   
Name: Anonymous
Date: 2012-12-12 8:46:55 AM
Comment:
The images are blank and result in a 404 if opened individually.
Title: Very nice   
Name: Thanigainathan
Date: 2011-03-28 2:36:03 PM
Comment:
Hi,

The article is very nice. So you mean only the parent of the list property can modify its state. Will this be sort of restricting the features of collections ?

Thanks,
Thani






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-24 12:04:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search