This will help us to manage dependencies between classes. We have also used Interfaces to communicate between InterestCalculator and BankAccount class. So this is the implementation of Single Responsibility Principle. If we want to add any new business rule for the Calculation of Interest, we don't need to change BankAccount class.Īnd also InterestCalculator class requires no changes, in case we need to add a new Property AccountHolderName. Now our BankAccount class is just responsible for properties of the bank account. Public decimal CalculateInterest(IBankAccount account) Public class InterstCalculator : IInterstCalculator Look at the code below: public interface IBankAccount In this paper, Parnas compared two different strategies for decomposing and. Martin as a part of what he calls Principles of Object Oriented Design. The term itself was introduced by Robert C. It appeared in the December issue of the Communications of the ACM, Volume 15, Number 12. Single responsibility principle is also known as SRP is a computer programming principle that consists of classes, functions or modules that can’t have more than one responsibility. So, in your example, the calculatePay method will need to be changed whenever new types of Employees are required. Now let's try to implement SRP to resolved this violation. Parnas published a classic paper entitled On the Criteria To Be Used in Decomposing Systems into Modules. One often missed detail of the Single Responsibility Principle is that the 'reasons for change' are grouped by use-case actors (you can see a full explanation here). This violates Single Responsibility Principle. We have 2 different types of reason to change one class. One is changing on features where as other one is impacting the functionality. This are totally different type of change request. Some new rule has been introduced to calculate interest.Please add a new Property AccountHolderName.Robert Martin publishes the book Agile Software Development: Principles, Patterns, and Practices. The Single Responsibility Principle doesnt appear on this list. Now look at the few change Request we received from business: Following OCP would lead to long inheritance chains and also a violation of another design principle. Here, BankAccount class contains the properties of account and also calculate the interest of account.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |