solid-principles

Interface Segregation Principle- Program to an interface

我的梦境 提交于 2019-11-26 15:47:23
问题 I was reading about SOLID and other design principles. I thought ISP was the same as "Program to an interface, not an implementation". But it looks like these are different principles? Is there a difference? 回答1: ISP is focused on the idea of each interface representing one discrete and cohesive behavior. That is, each logical group of things an object should do would map to a single specific interface. A class might want to do several things, but each thing would map to a specific interface

Learning Single Responsibility Principle with C#

守給你的承諾、 提交于 2019-11-26 10:14:28
问题 I am trying to learn the Single Responsibility Principle (SRP) but it is being quite difficult as I am having a huge difficult to figure out when and what I should remove from one class and where I should put/organize it. I was googling around for some materials and code examples, but most materials I found, instead of making it easier to understand, made it hard to understand. For example if I have a list of Users and from that List I have a class Called Control that does lots of things like

Are there any rules for OOP?

故事扮演 提交于 2019-11-26 10:14:02
问题 Recently I heard that there are 9 rules for OOP(Java). I know only four as Abstraction, Polymorphism, Inheritance and Encapsulation. Are there any more rules for OOP? 回答1: Seems like what you're looking for are the Principles of Object-Oriented Design. Summarized from Agile Software Development Principles, Patterns, and Practices. These principles are the hard-won product of decades of experience in software engineering. They are not the product of a single mind, but they represent the

What is an example of the Single Responsibility Principle? [closed]

纵然是瞬间 提交于 2019-11-26 09:34:56
问题 Can someone give me an example of the Single Responsibility Principle? I am trying to understand what it means, in practice, for a class to have a single responsibility as I fear I probably break this rule daily. 回答1: Check out the Solid description. Unless you ask for something more specific, it will be hard to help more. Single responsibility is the concept of a Class doing one specific thing (responsibility) and not trying to do more than it should, which is also referred to as High

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

蹲街弑〆低调 提交于 2019-11-26 08:44:37
问题 Can you explain Liskov Substitution Principle (The \'L\' of SOLID) with a good C# example covering all aspects of the principle in a simplified way? If it is really possible. 回答1: (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 throws

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