solid-principles

Learning Single Responsibility Principle with C#

丶灬走出姿态 提交于 2019-11-27 06:11:17
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 Send a greeting and goodbye message when a user comes in/out, verify weather the user should be able

DDD Approach to Access External Information

不想你离开。 提交于 2019-11-27 05:23:07
I have an existing bank application classes as shown below. The banks account can be of SavingsBankAccount or FixedBankAccount. There is an operation called IssueLumpSumInterest. For FixedBankAccount, the balance need to be updated only if the owner of the account has no other account. This demands the FixedBankAccount object to know about other accounts of the account owner. How to do this by following SOLID /DDD/GRASP/Information Expert pattern? namespace ApplicationServiceForBank { public class BankAccountService { RepositoryLayer.IRepository<RepositoryLayer.BankAccount> accountRepository;

Are there any rules for OOP?

强颜欢笑 提交于 2019-11-27 02:43:35
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? 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 integration and writings of a large number of software developers and researchers. Although they are presented

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,

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

两盒软妹~` 提交于 2019-11-26 23:35:02
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. jgauffin (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 ArgumentNullException if an argument is missing and the sub class allows the argument to be null, also a LSP

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

雨燕双飞 提交于 2019-11-26 23:15:04
What is the dependency inversion principle and why is it important? Carl Seleborg 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 sites. Effectively, the DIP reduces coupling between different pieces of code. The idea is

Does the Single Responsibility Principle work in OOP?

心已入冬 提交于 2019-11-26 21:21:18
问题 I am struggling to understand how the Single Responsibility Principle can me made to work with OOP. If we are to follow the principle to a tee, then are we not left with many classes, many of which may just have one method each? If we don't follow the principle exactly, then what is the point in the principle? 回答1: I like to state the single responsibility principle this way: "Every thing you write -- every module, class, interface, or method, should have one job. It should do the whole job

Can anyone provide an example of the Liskov Substitution Principle (LSP) using Vehicles?

我只是一个虾纸丫 提交于 2019-11-26 18:56:59
问题 The Liskov Substitution Principle states that a subtype should be substitutable for that type (without altering the correctness of the program). Can someone please provide an example of this principle in the domain of vehicles (automotives)? Can someone please provide an example of a violation of this principle in the domain of vehicles? I've read about the square/rectangle example, but I think that an example with vehicles will give me a better understanding of the concept. 回答1: For me, this

Can't seem to understand SOLID principles and design patterns [closed]

蹲街弑〆低调 提交于 2019-11-26 18:53:53
问题 I'm trying to get into OOP lately, and I'm having trouble with SOLID principles and design patterns. I see why people use them, and I really want to use them too, but I can't wrap my head around developing my classes to the specifications. I would really appreciate anything that would help my understanding of such. 回答1: I've taken a class in college that spent two weeks around design patters, and read the Gang of Four book to no avail. Understanding what each pattern served for and how to use