Skip to main content

Posts

Showing posts from 2010

Lists or Objects

"Our rule of thumb is that we try to limit passing around types with generics (the types closed in angle brackets). Particularly when applied to collections, we view it as a form of duplication. It's a hint that there's a domain concept that should be extracted into a type." Growing Object-Oriented Software, Guided by Tests - Steve Freeman, Nat Pryce, page 136)ExampleNot ideal - business logic will leak.Better - quotes are now encapsulated.Why?The benefit of the second approach is that you begin to force the collection to do the work. Consider a collection of quotes - using the first approach a developers' typical instinct would be to loop over the list and check each quote until the lowest quote was found. You could argue that this in turn violates the 'Tell Don't Ask' principle because very quickly you can find yourself digging down into objects. We would not do this with standalone objects, so collections sho…