Our Customer comes to us and likes what we have done setting up a way for them to find if a customer is active, but now they want to keep track of all the customers. We come up with the concept of a Customer Record Book and our client seems happy with that:
Our record book does its job of storing customers well but our client wants us to add a way to find all the active customers in it. Our first attempt at creating a way to find all the active customers looks like this:
The Filter method that we just created takes in the ActiveCustomerSpecification, creates a temporary list and then iterates through the customer list adding the active customers to the temporary list, once it is done it returns the temporary list. Our test passes but there are a couple of improvements we can make to this code. First of all, we don't need to create a temporary list or use an IList<Customer> we can leverage the yield keyword and IEnumerable<Customer> to make our code tighter:
This change will break our test since IEnumerable does not contain a definition for count. If we look at the available constructors for the List class we can see that List has a contructor for creating a list from IEnumerable. So we can easily fix our test:
Now we are able to find all active customers in a list.
Remember Me
a@href@title, strike
Theme design by Jelle Druyts
Pick a theme: BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2 BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Steven Rockarts
E-mail