Single-Responsibility-Principle | Sample implementation of Single Responsibility Principle
kandi X-RAY | Single-Responsibility-Principle Summary
kandi X-RAY | Single-Responsibility-Principle Summary
Sample implementation of Single Responsibility Principle.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Single-Responsibility-Principle
Single-Responsibility-Principle Key Features
Single-Responsibility-Principle Examples and Code Snippets
public interface Troll {
void attack();
int getAttackPower();
void fleeBattle();
}
@Slf4j
public class SimpleTroll implements Troll {
@Override
public void attack() {
LOGGER.info("The troll tries to grab you!");
}
@Override
pub
Community Discussions
Trending Discussions on Single-Responsibility-Principle
QUESTION
I have a factory to build cars... it a basic factory, it accepts name of a car, looks for all classes that implement ICar
, chooses the correct type based on car name and initializes the car using reflection.
ANSWER
Answered 2018-Oct-29 at 07:10It is better to inject dependencies (constructor, property, method) into your types. And it is best to avoid creating dependencies using new-operator.
To make it even better you should define an interface for you CarFactory
(ICarFactory
) and change your service to depend on that type.
In tests you could mock ICarFactory
and provide special implementations for your test cases.
QUESTION
Well i have got an Class that reads a Excel-file as template.
- The class converts the Excel File to a Java Object
- Adds Information to the template
- rewrites the Template with the added Informations
i was reading some stuff about the single-responsibility-principle and decided that i need to refactor my class, because its doing more than one thing.
iam just not sure if iam doing to much here ?
...ANSWER
Answered 2018-Aug-17 at 11:08From a first glance, this looks quite good to me.
The point is to have a meaningful amount of "responsibility" within a class/method. Just by reading the name of the class, and looking at the public methods it should be clear what that class can do for you, and how you interact with the class to actually get to these results.
Beyond that, methods should do something that is easy to test with unit tests.
Taking all the above ideas into account: yes, this looks good.
Where: I assume that your public static utility methods are used in more than one class, only then they should go into a distinct class. The only thing worth thinking about: do all the methods and classes need to be pubic? An external user of the overall solution (invoking it from a different package), does that client code really need all these public methods? Meaning: only make public what external client code is supposed to be using!
QUESTION
I am wondering whether there is a way to avoid repeating myself in passing Request.Headers
into every service method?
ANSWER
Answered 2017-Jul-28 at 23:16One possibility would be to create a service to extract the current Request
.
If hosting it in IIS, then the ASP pipeline stores the Web API message object on the current HttpContext
.
Once that exists, you can access it via
QUESTION
In the last week I've been trying to apply MVVM Pattern to Universal Windows Plataform, in the most elegant possible way, that means apply SOLID principles and some popular design patterns.
I've been trying to reproduce this exercise from this link: http://www.sullinger.us/blog/2014/7/4/custom-object-validation-in-winrt
Also the link is for Windows 8 apps it also applies to Windows 10 apps according to MSDN answer at this forum: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/05690519-1937-4e3b-aa12-c6ca89e57266/uwp-what-is-the-recommended-approach-for-data-validation-in-uwp-windows-10?forum=wpdevelop
Let me show you my classes, this is my view my final view:
...ANSWER
Answered 2017-Apr-09 at 00:11Ok Finally I was able to make this code work, it has some fixes but I was able to understand it and also solve it on my own, before I publish my answer because i have two answers for this problem, I'll like to apologize to the community, I didnt want to ask for help so that you could do it for me, it wasnt my intention, if it looked like that, I'm sorry, i'll try to sound less needy.
Well down to the solution:
the main issue of the code I've published is in the abstract method Validate, since you gotta write your own validation for each field and also this is where you control the adding and removal of error messages, so I wrote a Validate Method like this one:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Single-Responsibility-Principle
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page