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

Doing It Wrong

Doing it the simplest way that could possibly work would mean simply exposing the internal state of the Customer class by creating a public field of List<Order>.  The listing below shows what this might look like, and a couple of tests that show the required functionality (and currently pass):

 

At first glance, this appears to solve the requirements of the system.  Now let's add a few more tests to reveal the weaknesses in this approach, and refactor it to improve things.


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-04-19 11:01:10 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search