You have AuthorDAO
which is the class that should be doing all interactions with the persistence layer, ex. a database.
It isn't obvious in your example because your AuthorEntityLoadService
has similar methods which just delegate to the DAO layer.
As your project and requirements grow, you will see that more methods are required for this class. These methods will be responsible for doing more than just CRUD operations on the DAO layer. They might need to interact with other services, internal or external. They might need to do multiple DAO calls.
The Single Responsibility in this case is to provide services for interacting with AuthorEntity
instances.
It is on of many correct ways of implementing what you are proposing.
More specifically, my opinion on
Also I am always confused about how to decide responsibility of the class because any class can have many methods and each method can be performing something different.So should they be separated in different class?
Just because you have many methods doing different things, doesn't mean the responsibility isn't shared. AuthorEntityLoadService
which I would just call AuthorEntityService
manages AuthorEntity
instances at the service layer. Image if you had one Class with one method for each of create, update, retrieve, delete an AuthorEntity
. That wouldn't make much sense.
And on
Any suggestions on how to decide what the responsibility is from the perspective a class?
As further reading, try http://java.dzone.com/articles/defining-class-responsibility