Daniel Cazzulino on 'sealed'

Daniel Cazzulino offers some useful advice if you feel you have to seal classes (although from the title of the post I think its easy to see how Daniel feels about sealed in general). If I had to sum it up in one word I’d say “interfaces”. I’m quite fond of interfaces, and I’ve found thinking about your design in terms of interfaces rather than classes to be very helpful because it helps you clearly seperate the essential behaviors and properties of something from the implementation detail. If up-front you’re thinking “hey, this data may not be coming from a database” or “what if we wanted to write this out to something other than a file” it can often help you take the next step up abstraction wise, and also see what things you’re taking for granted (possibly incorrectly). Of course creating interfaces is much less useful if your methods refer to the the implementation classes rather than the interfaces themselves, and likewise type checks and casts should be done against the interface. Aside from the design benefits I think interfaces also help a great deal with writing software that’s easy to test.