Reference articles:
- Why use private or protected
- Testability
I am fond of
Rocky Lhotka's CSLA framework before and when i shifted to be test-driven, there are some constructs in CSLA that i'm beginning to dislike. I like the broken rule tracking, n-tier ready setup, etc. but i'm beginning to hate the static creation methods and having the default constructor as private. CSLA is very good in encapsulation and i really think that encapsulation sometimes (or maybe oftentimes) sacrifices testability.
The first article (Why use private or protected) appealed to me when i was refactoring a method using some other private methods. I know that you should only do black box testing but if the test for the exposed method fails, i know that the error can be anywhere in it and also in the private methods that it is using. Having a separate test for each method can easily pinpoint a breaking change. I decided to expose these private methods so they can have their accompanying automated unit tests. I am beginning to have this dilemma if i am designing classes to be testable, do i need to have to use private or protected? I agree that developing frameworks is an exemption to this rule but oftentimes, we are just developing applications.
The second article basically demonstrates his own metrics for testability.
I used to be fan of a class with readonly properties set-able only in the class' constructor. My purpose for designing classes like this is i want to have a restriction that all the properties which are required first to be set before fully constructing an instance of the said class. I found my previous design to be too restrictive when you are designing classes to be testable. My usual approach these days is to have those properties as read-write and have some broken rule tracking in the class similar to CSLA's BrokenRulesCollection.
Posted
09-14-2006 7:39 PM
by
jokiz