## SRP Violated or not?

Moderatoren: pmueller, SE - Design and Construction

AizazZaidee
BASIC-Programmierer
Beiträge: 106
Registriert: 20. Apr 2016 22:49

### SRP Violated or not?

Hi,
I am very confused about SOLID violations because I have read different articles on different websites. So according to someone something is violated but then I read counter arguments. So I am very confused how to handle such things in exams???

For example the following code has SIP violated or not?

Code: Alles auswählen

class Person {
private IFormatter formatter;

public Person(IFormatter formatter){
this.formatter = formatter;
}

public string FirstName { get; set; }
public string LastName  { get; set; }
public Gender Gender { get; set; }
public DateTime DateOfBirth { get; set; }

public string Format(Enum formatType) {

switch(formatType.Type) {
case formatType.JSON:
return formatter.json();

case formatType.FirstAndLastName:

return formatter.firstAndLastNameString();

default:

return SomeRuntimeException("Formatter Not Found");
}
}
}
(This code has been taken from some website and then edited a little bit, please ignore any bracket or semicolon error)

I am just trying to understand these concepts because I'll use them my whole life

Thanking in anticipation
Zuletzt geändert von AizazZaidee am 6. Jul 2018 09:18, insgesamt 1-mal geändert.

pmueller
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

### Re: SIP Violated or not?

Hi,

I'm not sure waht you mean with SIP? ISP or DIP or something else entirely?
In general these principles are just that - principles. Like you said, sometimes you can find arguments for both sides, or violating a principle leads to other properties, e.g. faster code at runtime - at the loss of maintainability. There are always tradeoffs.
In the exam, you will have to argue. If your arguments are sound you will receive points accordingly.

Best,
Patrick

AizazZaidee
BASIC-Programmierer
Beiträge: 106
Registriert: 20. Apr 2016 22:49

### Re: SRP Violated or not?

Hi,
Thanks for your reply. I am sorry, it was a typo. it is SRP (Single Responsibility Principle). Thanks for clarifying exam related query.

Thanks.