principles

What is the dependency inversion principle and why is it important?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 08:39:16
问题 What is the dependency inversion principle and why is it important? 回答1: Check this document out: The Dependency Inversion Principle. It basically says: High level modules should not depend upon low-level modules. Both should depend upon abstractions. Abstractions should never depend upon details. Details should depend upon abstractions. As to why it is important, in short: changes are risky, and by depending on a concept instead of on an implementation, you reduce the need for change at call

What is the EAFP principle in Python?

别来无恙 提交于 2019-11-25 22:23:26
问题 What is meant by \"using the EAFP principle\" in Python? Could you provide any examples? 回答1: From the glossary: Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false. This clean and fast style is characterized by the presence of many try and except statements. The technique contrasts with the LBYL style common to many other languages such as C. An example would be