Can you explain Liskov Substitution Principle with a good C# example? [closed]

(This answer has been rewritten 2013-05-13, read the discussion in the bottom of the comments) LSP is about following the contract of the base class. You can for instance not throw new exceptions in the sub classes as the one using the base class would not expect that. Same goes for if the base class … Read more

Difference between Single Responsibility Principle and Separation of Concerns

Single Responsibility Principle (SRP)- give each class just one reason to change; and “Reason to change” == “responsibility”. In example: Invoice class does not have a responsibility to print itself. Separation of Concerns (since 1974). Concern == feature of system. Taking care of each of the concerns: for each one concern, other concerns are irrelevant. … Read more

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

What Is It? The books Agile Software Development, Principles, Patterns, and Practices and Agile Principles, Patterns, and Practices in C# are the best resources for fully understanding the original goals and motivations behind the Dependency Inversion Principle. The article “The Dependency Inversion Principle” is also a good resource, but due to the fact that it … Read more

What is an example of the Liskov Substitution Principle?

A great example illustrating LSP (given by Uncle Bob in a podcast I heard recently) was how sometimes something that sounds right in natural language doesn’t quite work in code. In mathematics, a Square is a Rectangle. Indeed it is a specialization of a rectangle. The “is a” makes you want to model this with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)