I have the following strange question. Lets say we have a class BlackJackGame and this class contains the BlackJackGame algorithm for electing a winner. Same class though contains the main method for starting the game. This main method in some sense is violating the principle of Single Responsibility for a class. In addition lets say we place one more method for printing the winner in some format. Lets say this method is also static, is this method breaking the responsibility principle any more than the main method. And then what, lets say we say that it is breaking. Does this mean we should create. Now lets presume we also have a utility method that parses the arguments coming from the command line and place it as static method as well.
1 Main class to hold the Main method, 1 Print class to hold the Print method and 1 ArgumentParser class holding a single static method to parse the arguments.
I will visualize it like this:
public class BlackJackGame{
//returns the wining player
public Player play(Deck deck) {
// some logic here
}
// deck is a class holding the Deck.
public static Deck parseArguments(String args[]) {
// logic here
}
public static void printPlayer(Player winner) {
// some logic here
}
public static void main(String args[]) {
Deck deck = createDeck(args);
BlackJackGame game = new BlackJackGame();
Player winner = game.play(deck);
printWinner(winner);
}
}
If we follow the Single Responsibility Principle. Does it reay matter and is it more correct if we had:
public class BlackJackGame{
//returns the wining player
public Player play(Deck deck) {
// some logic here
}
}
public class Main{
public static void main(String args[]) {
Deck deck = DeckCreator.createDeck(args);
BlackJackGame game = new BlackJackGame();
Player winner = game.play(deck);
Printer.printWinner(winner);
}
}
Isn't this a little bit extreme ???? Like Single Responsibility taken into extremities ?
I am asking this question because it popped up during a code review I requested here. codereview.stackexchange.com/questions/172469/… I kind of have feeling that it is a bit Single Responsibility Principle taken into extremeties to be honest.