design-principles

Liskov substitution principle - no overriding/virtual methods?

£可爱£侵袭症+ 提交于 2019-11-27 09:23:25
问题 My understanding of the Liskov substitution principle is that some property of the base class that is true or some implemented behaviour of the base class, should be true for the derived class as well. I guess this would mean when a method is defined in a base class, it should never be overrided in the derived class - since then substituting the base class instead of the derived class would give different results. I guess this would also mean, having (non-pure) virtual methods is a bad thing?

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

谁都会走 提交于 2019-11-27 01:18:44
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. 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 Cohesion. Classes dont often start out with Low Cohesion, but typically after several releases and different

What is the reasoning behind the Interface Segregation Principle?

一曲冷凌霜 提交于 2019-11-27 00:55:16
问题 The Interface Segregation Principle (ISP) says that many client specific interfaces are better than one general purpose interface. Why is this important? 回答1: ISP states that: Clients should not be forced to depend on methods that they do not use. ISP relates to important characteristics - cohesion and coupling. Ideally your components must be highly tailored. It improves code robustness and maintainability. Enforcing ISP gives you following bonuses: High cohesion - better understandability,

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

Why Choose Struct Over Class?

旧街凉风 提交于 2019-11-25 22:47:04
问题 Playing around with Swift, coming from a Java background, why would you want to choose a Struct instead of a Class? Seems like they are the same thing, with a Struct offering less functionality. Why choose it then? 回答1: According to the very popular WWDC 2015 talk Protocol Oriented Programming in Swift (video, transcript), Swift provides a number of features that make structs better than classes in many circumstances. Structs are preferable if they are relatively small and copiable because