Why do we need testable object-oriented development)

Source: Internet
Author: User
Original article: Why you shoshould think about toop-testable Object Oriented Programming Author: Roy osherove, chief architect of typemock --- The art of unit testing: author with examples in. net 

I think Object Oriented Design \ Programming) it's time to make some changes.

the pursuit of quality and testability and continuous integration has begun in the industry.

we need to consider a simple fact: in many cases, there are some conceptual conflicts between a pure OOD and a testable design. I once wrote an article that fxcop removed some testable features in pursuit of pure object-oriented features (of course, the author despised the fxcop team ).

the following are some testable designs that require" hiding "for Ood/oop) example of the design proposal "public.

OOD: do not disclose private members or methods that do not need to be used by other developers.

testable: dependency injection through interfaces, open the setters method to make public or replace private members of those objects.

OOD: classes are closed unless you need to extend them to others.

testable: sealing is not allowed by default (unless security considerations are taken into consideration) so that users can reuse your methods and override according to their testing needs.

OOD: Your method is virtual only when you need to override your method. -- Because Java is virtual by default, the author prefers Java at this point.

testable: by default, your method is virtual, in this way, those who need to write tests can inherit and override your methods to remove some dependencies.

OOD: Use the singleton method to ensure that only one instance is used and no one is allowed to touch private objects.

testable: allow replacing a singleton object to remove dependencies in the test.

OOD: Unless necessary, the default type is private or interna.

testable: Open the types of APIs that you think are useful for testing projects.

OOD: do not add unnecessary APIs.

testable: add a specific API (method, interface, especially type) for testing, these are required for testing.

What if we add "testability" to the Ood vocabulary?

"Testable Object Oriented Design:Tood "(Testable object-oriented design)

"Testable object oriented programming:Toop "(Testable Object-Oriented Programming)

tood and toop make your design more solid

(Refer to Bob Martin's solid design principles. This series of principles persists, including the single responsibility principle, open closed principle, and liskov substitution principle ), interface segregation principle and dependency inversion principle ).)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.